SCRMaps
/
Sign in

The player loop

Once per cycle, once per player.

6 min read

EUD Editor 3 calls beforeTriggerExec once per trigger cycle. Logic that must run continuously goes there.

function beforeTriggerExec(){
    EUDPlayerLoop()();

    updateStatusLine();

    EUDEndPlayerLoop();
}

function afterTriggerExec(){
}

Code between EUDPlayerLoop()() and EUDEndPlayerLoop() runs once per player, and inside it CurrentPlayer and f_getcurpl() refer to that player. Omit the loop and every player ends up sharing one set of values.

The loop covers player indices 0 through 7 - empty slots, players who left, and computers alike. So anything meant for humans only has to be filtered.

var pid = f_getcurpl();
if(pid <= 6){
    // 사람 플레이어에게만 적용
}

But filtering on the slot number is not the same question as whether anyone is in that slot. To iterate only the players actually in the game, use EUDLoopPlayer: it checks playerexist internally, so empty slots and players who have left are skipped for you.

foreach(p : EUDLoopPlayer()) {          // 기본값이 "Human"입니다 / defaults to "Human"
    setcurpl(p);
    updateStatusLine();
}

foreach(p : EUDLoopPlayer("Human", Force1, "Zerg")) { }   // 더 좁히려면
All three arguments are optional. Most of "my player count is wrong because somebody left" disappears simply by iterating with this.

To include computer players, EUDPlayerLoop()() and EUDEndPlayerLoop() are the pair. That one walks every active player including computers, and when it ends it puts CurrentPlayer back to whatever it was before the loop - so you do not have to save and restore it yourself.

The four functions that handle CurrentPlayer
getcurpl()Reads cpcache, refreshing from the real CurrentPlayer only when the two differ - so calling it repeatedly is cheap.
setcurpl(cp)Sets CurrentPlayer and cpcache together.
addcurpl(n)Adds to both.
setcurpl2cpcache()Puts CurrentPlayer back to what cpcache holds - the restoring half of a borrow.

CurrentPlayer does not have to be a player. It is one global that some trigger actions happen to consult, and the CP trick works precisely by storing something that is not a player in it.

Sign in to track your progress