EPScript 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. |
| // 주석 | 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.
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.
The language has loops, but shipped scripts barely use them. The trigger cycle is already a loop, so most repetition is left to the cycle and filtered with conditions instead.
