SCRMaps
/
Sign in

Writing it in Python instead

Using eudplib directly instead of epScript brings Python's own syntax with it.

9 min read

epScript is a language laid on top of eudplib. Go one level down and you use eudplib from Python directly, which brings all of Python with it - lists, dictionaries, functions, modules - for building the map.

Trigger(
    players=[P1],
    conditions=[Accumulate(P1, AtLeast, 50, Ore)],
    actions=[SetResources(P1, Subtract, 50, Ore)],
    preserved=True,
)
The same shape as a classic trigger, produced by Python code.

The confusing part is which code runs when. Python's own if and for run at compile time and decide how many triggers get made. To decide during the game you need eudplib's own - EUDIf, EUDWhile. Mix them up and it compiles and then nothing happens in game.

The library lives under Data/eudplibdata in the euddraft folder. When an argument order is unclear, opening that beats any document - all the more because a call with the arguments in the wrong order compiles quietly.

And there is one trap you must know when using eudplib from Python directly - the same thing that explains why the double parentheses and EUDEndIf() exist.

An EUD control structure has to emit triggers for every branch at compile time, so it can only ride Python constructs that always execute: an if with an always-true condition, a for-in over a one-shot iterator, a with.

So Python's elif and else cannot be used - and the problem is that it is silent. Every eudplib control statement's __bool__() returns True, so an elif or else attached to one is never evaluated: the code inside does not reach the map, and a mistake in it may not even raise. Write the else branch as if EUDElse()(): instead.

The same reason rules out try/except and match/case. A merged EUDIf(cond) is caught for you, because EUDIf()'s own __bool__ is what gets called. And EUDEndIf() exists because Python can run code at the start of an if but not at the end of its block - for and with can run code at the start, middle and end, which is why EUDLoopCUnit needs no End.

eudplib: triggers and control flow