查看: 2018|回复: 2

[有事请教] 如何 在function内获取当前事件的id

[复制链接]
梦石
0
星屑
224
在线时间
28 小时
注册时间
2020-3-16
回帖
6
发表于 2021-9-22 16:15:24 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
        monstermove = function() {
       
                                   var a = this._eventId;
           $gameMap.event(a).moveStraight(6);
            
        };

用一个事件执行monstermove,发现无法获取本事件的id,请大佬指点下
梦石
0
星屑
3486
在线时间
294 小时
注册时间
2020-1-27
回帖
180
发表于 2021-9-22 23:45:32 | 显示全部楼层
this 不会自动往下传的.
调用的时候得 : monstermove.bind(this)();
this才会跟着走.

或者直接拿当前运行事件的 evid: (但不包括并行运行那些.
function getEvid() {
    if (typeof $gameMap === "undefined" && $gameTroop === "undefined") {
        return 0;
    }
    var target = $gameMap
    if ($gameTroop && $gameTroop._inBattle) {
        target = $gameTroop
    }

    if (target._interpreter === undefined) {
        return 0;
    }
    if (target._interpreter._list === undefined) {
        return 0;
    }
    if (!target._interpreter._list) {
        return 0;
    }
    if (target._interpreter._list.constructor.name !== "Array") {
        return 0;
    }
   
    return target._interpreter._eventId;
}
事件需要递归到子事件.我没写递归. 你自己搞.
回复

使用道具 举报

梦石
0
星屑
224
在线时间
28 小时
注册时间
2020-3-16
回帖
6
 楼主| 发表于 2021-9-23 01:13:52 | 显示全部楼层
zths 发表于 2021-9-22 23:45
this 不会自动往下传的.
调用的时候得 : monstermove.bind(this)();
this才会跟着走.

谢谢大佬指点,我基础差,还要多加学习
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部