Whilevarn: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
One (talk | contribs)
No edit summary
Fox (talk | contribs)
I will put in a more usual example
Line 5: Line 5:
Caution: Poor execution or endless loops will cause your game to close without error or simply stall and crash!
Caution: Poor execution or endless loops will cause your game to close without error or simply stall and crash!


An example:
This example will set up the palette of the floor from all sectors on the map:
<pre>
<pre>
gamevar TEMP 0 2
onevent EVENT_LOADACTOR
gamevar RANDX 0 2
  whilevarvarn TEMP NUMSECTORS
gamevar RANDY 0 2
  {
gamevar RANDZ 0 2
     setsector[TEMPSECTORS].floorpal 0
 
    addvar TEMP 1
state troopspawnstate
  }
    setvar TEMP 0
endevent
    whilevarn TEMP 10
     {
        randvar RANDX 2048
        mulvarvar RANDX TEMP
        randvar RANDY 2048
        mulvarvar RANDY TEMP
        randvar RANDZ 2048
        mulvarvar RANDZ TEMP
     
        espawn EXPLOSION2          // Spawn an explosion at a random location
        setactor[RETURN].x RANDX  // that gets progressively further away the
        setactor[RETURN].y RANDY  // longer that the code executes.
        setactor[RETURN].z RANDZ
 
        addvar TEMP 1
    }
ends
 
. . .
 
state troopcode
. . .
 
ifaction ATROOPHIDE            // Execute the code while the Liztroop
    state troopspawnstate      // Captain is teleporting in/out.
ifaction ATROOPREAPPEAR
    state troopspawnstate
 
. . .
ends
</pre>
</pre>


[[Category:EDuke32 specific commands]]
[[Category:EDuke32 specific commands]]

Revision as of 12:13, 8 August 2009

whilevarn <gamevar> <value> { code to execute }

Executes the code in the curly braces as long as <gamevar> does not equal <value>. This is a simple while loop.

Caution: Poor execution or endless loops will cause your game to close without error or simply stall and crash!

This example will set up the palette of the floor from all sectors on the map:

onevent EVENT_LOADACTOR
  whilevarvarn TEMP NUMSECTORS
  {
    setsector[TEMPSECTORS].floorpal 0
    addvar TEMP 1
  }
endevent