Whilevarn: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Fox (talk | contribs)
No edit summary
No edit summary
Line 8: Line 8:
<pre>
<pre>
onevent EVENT_LOADACTOR
onevent EVENT_LOADACTOR
  setvar TEMP 0
   whilevarvarn TEMP NUMSECTORS
   whilevarvarn TEMP NUMSECTORS
   {
   {
Line 14: Line 15:
   }
   }
endevent
endevent
</pre>
There's no variable keeping the number of sprites in the map. The sprites may be randomly arranged throughout the array with a maximum of 16384 entries. An example of a correct per-sprite loop:
<pre>
setvar sectnum 0
whilevarvarn sectnum NUMSECTORS
{
  headspritesect I sectnum
  setvarvar HEAD I
  whilevarn I -1 {
    // LOOP CODE
    nextspritesect I I
    ifvarvare I HEAD setvar I -1 // Break the loop
  }
  addvar sectnum 1
}
</pre>
</pre>


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

Revision as of 19:22, 18 September 2010

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
  setvar TEMP 0
  whilevarvarn TEMP NUMSECTORS
  {
    setsector[TEMPSECTORS].floorpal 1
    addvar TEMP 1
  }
endevent

There's no variable keeping the number of sprites in the map. The sprites may be randomly arranged throughout the array with a maximum of 16384 entries. An example of a correct per-sprite loop:

setvar sectnum 0
whilevarvarn sectnum NUMSECTORS
{
  headspritesect I sectnum
  setvarvar HEAD I
  whilevarn I -1 {
    // LOOP CODE
    nextspritesect I I
    ifvarvare I HEAD setvar I -1 // Break the loop
  }
  addvar sectnum 1
}