EPScript is a scripting language for EUD work and its syntax looks broadly like C or JavaScript. Open a shipped map's script, though, and the syntax in use is startlingly narrow: var, function, if/else and return account for almost all of it.
| var name = 0; | Declare a variable - local inside a function, global outside one. |
|---|---|
| function name(){ } | Declare a function, which may take arguments and return a value. |
| // comment | A line comment. |
| if(cond){ } else { } | A conditional, with else if available. |
|---|---|
| return value; | Return a value. |
| && | Logical and - in practice the only operator used to chain conditions. |
| == / != | Equal and not equal. |
| + - * / % | Arithmetic and remainder. |
A condition can be a trigger condition rather than just a value comparison. That is the heart of EPScript: the conditions and actions you already know are all callable as functions. Deaths() is a condition so it goes inside the if; SetDeaths() is an action so it stands as a statement.
function giveReward(){
var amount = 0;
if(Deaths(CurrentPlayer, AtLeast, 100, "Level") && Command(CurrentPlayer, AtLeast, 1, "Terran Marine")){
amount = 500;
}
if(amount == 0){ return; }
SetDeaths(CurrentPlayer, Add, amount, "Gold");
DisplayText("\x13\x07보상을 받았습니다");
}Declarations must precede use. There is no hoisting, so a global a function reads has to be declared above it - which is why globals are conventionally gathered at the top of the file.
When an order cannot be arranged - two functions calling each other, say - you can declare one without a body first: function square(x) : None; and the real body goes anywhere below.
The outermost loop is the trigger cycle itself, so code that runs every cycle tends to leave repetition to the cycle and filter with conditions - which is why simple scripts show few loops. But the language has for, while, foreach, switch, epdswitch and once, and modern maps use all of them. In particular, a loop that unrolls at compile time and a loop that runs in game are entirely different things.
Loops and branches in fullThe rest of the declaration syntax