SCRMaps
/
Sign in

The Current Player trick

How to hold an address in a variable and write to it - the only way EUD follows a pointer.

8 min read

The problem is this. You have found a unit's structure offset and put the address in a variable. Now you want to write to that address. But SetMemory(thatVariable, Add, 200) adds 200 to the value you stored - it does not go to the address you stored and add 200 there.

The player field of a death trigger is a constant; you cannot put a variable in it. So you do it the other way round: leave the field as CurrentPlayer, and change what CurrentPlayer reads.

// 현재 플레이어는 0x6509B0 에 들어 있는 값입니다.
// P1의 트리거가 돌 때 0, P2일 때 1, ... P8일 때 7.
SetMemory(0x6509B0, SetTo, 12345);
SetDeaths(CurrentPlayer, Add, 1, "Terran Marine");
// 위 두 줄은 플레이어 12345의 마린 데스값을 1 올립니다.
CurrentPlayer is simply whatever 0x6509B0 holds.

So with an EPD you can write anywhere. These two do the same thing:

SetMemory(ptr, SetTo, X);

// 와 같다
SetMemory(0x6509B0, SetTo, (ptr - 0x58A364) / 4);
SetDeaths(CurrentPlayer, SetTo, X, "Terran Marine");
This is where the EPD formula earns its keep.

Once you are holding a structure offset, moving to a field happens in CP space too. You are in a world of addresses divided by four, so stepping to a field 0x08 along means adding 0x08 divided by four.

SetMemory(0x6509B0, SetTo, EPD(CUnit(i)));   // 유닛을 가리킨다
SetMemory(0x6509B0, Add, 0x08 / 4);          // 체력 필드로 옮긴다
SetDeaths(CurrentPlayer, Add, 200, "Terran Marine");  // 체력을 올린다
256 hit points here is 1 in game.

Always put it back. 0x6509B0 is global and every trigger that runs after yours reads it as a player number. Leave it changed and all of them write somewhere else - and the symptom shows up in a feature that looks unrelated, not where you made the change.

You will rarely write this by hand now - epScript's dwwrite_epd and friends do it for you. The reason to know it is that it explains why the functions ending in _cp are faster, and why something unrelated breaks right after code that touched CP.

PTR and EPD
Sign in to track your progress