SCRMaps
/
Sign in

Order and the trigger cycle

The same trigger gives a different result depending on where it sits.

3 min read

Each cycle, triggers are evaluated player by player from P1 to P8, and within a player from the top of the file down. Not knowing this order is how you end up with bugs you cannot reproduce.

Say one trigger adds one to a counter and another fires when that counter hits 120. With the adder above, both happen in the same cycle; with it below, the second fires a cycle late.

Trigger { -- 이 트리거가 위에 있으면 같은 사이클에 발동된다
	players = {P8},
	conditions = {
		Always();
	},
	actions = {
		SetDeaths(P8, Add, 1, "SpawnTimer");
		PreserveTrigger();
	},
}

Trigger {
	players = {P8},
	conditions = {
		Deaths(P8, AtLeast, 120, "SpawnTimer");
	},
	actions = {
		SetDeaths(P8, SetTo, 0, "SpawnTimer");
		CreateUnit(1, "Zerg Zergling", "Spawn Point", P8);
		PreserveTrigger();
	},
}
In this order, the spawn happens the very cycle SpawnTimer reaches 120. Swap the two triggers and it lags to 121 - one cycle late.

If A writes a value and B reads it in the same cycle, the order of those two triggers is the specification. Re-sorting your trigger file later will silently change behaviour.

Keep interdependent triggers next to each other, and leave a comment saying why they are in that order.

Sign in to track your progress