Tier 2

External proceduress and Return code

EMC Script would be only an expanded calculator without external procedures. They're performing tasks related to the object that can not be complete using pure EMC. Note that EMC is only language interpreted by Dune 2 itself, not the program executed by CPU.

What the BUILD.EMC provides? Here's an anwer: You can:

As far as I know the UNIT.EMC can control many more behaviors of the units. For example if the unit is requested to move the script's responsible to move that unit etc. However I am not competent to provide more informations.

OK. How to call the external routine? Here's an example script

  1. Push 60
  2. Exec Delay()
  3. AddSP 1
This piece of code should delay the script for about one second (it's dependent on game speed). You're wondering what the Push and AddSP are doing here? Push provides the arguments for a routines. The routine will access those arguments by looking on the stack (more about it in next section). But it won't pop this values. So we must do it manually. AddSP will do it for us. It retrieves the stack space just by adding desired number to stack pointer (SP). (Note that the stack grows in up direction so Push will decrease this pointer). Remember that you must still obey FILO rule that forces you to push arguments in reverse order.

In most cases the function will return a value called return code (RC). This can be for example information whether the harvester is empty after we flushed whole cargo. There are special functions provided to access return code. They are:

Jumps, Loops and Condition codes

To immediately jump from one place in script to another you can use Goto command. As argument put the name of the label of the desired place. Additionally you can make a condition upon which the jump is performed. How this works? If the last value on stack is equal to zero the script continues from the specified label. In another case nothing happens. Note that the Eval command can calculate boolean expressions. This means that there is almost infinite number of possible conditions.

Let's look at the example which contains both usage of external procedures, return code and condition codes. This piece of script is taken from original BUILD.EMC. It's the part of the script of Refinery responsible on refining spice:

  1. Exec RefineSpice() ; refine one percent of cargo
  2. PushRC
  3. IfNotGo 5 ; exit loop if harvester is empty
  4. Goto 1 ; if not continue
  5. ...
Note that there is no need to retrieve stack space because IfNotGo (you can call this also ElseGo or whatever) do pop the value from stack. Clear to a degree? If so you can say about yourself as an expert. However to achieve master rank you must read Tier 3 aswell ;).