LoginSignup
0
0

More than 3 years have passed since last update.

単一のプラグインコマンドで複数のコモンイベントを呼び出す

Posted at

単一のプラグインコマン
ドで複数のイベントを呼び出します。
配列でコモンイベント番号のリストを渡し、その番号順で呼び出します。
使いたい方は以下のソースコードをコピペしてご自由にお使いください。
著作権は放棄しています。

/**
 * @param {Game_Interpreter} root 
 * @param {Number[]} eventIdList 
 */
function eventMultiCall(root,eventIdList){
    let target = root;
    for (let index = eventIdList.length-1; index >=0; index--) {
        const eventId = eventIdList[index];
        const newEvent = $dataCommonEvents[eventId];
        if(newEvent){
            target.setupChild(newEvent.list,target.eventId());
            target = target._childInterpreter;
        }
    }
}
PluginManager.registerCommand(PLUGIN_NAME,"multiCall" ,function(arg){
    const eventList = JSON.parse(arg.eventList)
    eventMultiCall(this,eventList);
});


原理

配列で[1,2,3]を渡した場合で説明します。
上記の処理では「コモンイベントの呼び出し」に使われるsetupChild()を利用しています。
コモンイベントはスタックとして処理されるので、配列を逆順でループして呼び出し関係を作ります。

まず現在実行しているイベントでコモンイベント3を呼び出した場合と同じ動きをします。
その後、コモンイベント3が実行される前に3から2を呼び出したように設定します。
さらに2から1を呼び出したのと同様の動きをします。
プラグインコマンドの処理が終わり、インタプリタはイベントが予約済みであるため、処理を移します。
それが連鎖的に発生し、予約のない状態である1から順に解決が始まります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0