Whilevarn: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by 4 users not shown)
Line 1: Line 1:
whilevarn <gamevar> <value> { code to execute }
'''whilevarn''' <[[gamevar]]> <value> { code to execute }<br>
'''whilevarvarn''' <[[gamevar]]> <[[gamevar]]> { code to execute }


Executes the code in the curly braces as long as <gamevar> does not equal <value>. This is a simple while loop.
Executes the code in the curly braces as long as <gamevar> does not equal <value>. This is a simple while loop.
Line 5: Line 6:
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
gamevar TEMP 0 0
gamevar RANDX 0 2
onevent EVENT_LOADACTOR
gamevar RANDY 0 2
  setvar TEMP 0
gamevar RANDZ 0 2
  whilevarvarn TEMP NUMSECTORS
  {
    setsector[TEMP].floorpal 1
    addvar TEMP 1
  }
endevent
</pre>


state troopspawnstate
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 TEMP 0
    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
<pre>
    }
setvar sectnum 0
ends
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>


. . .
{{varsuffix}}
 
state troopcode
. . .
 
ifaction ATROOPHIDE            // Execute the code while the Liztroop
    state troopspawnstate      // Captain is teleporting in/out.
ifaction ATROOPREAPPEAR
    state troopspawnstate
 
. . .
ends
</pre>


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

Latest revision as of 12:28, 1 October 2011

whilevarn <gamevar> <value> { code to execute }
whilevarvarn <gamevar> <gamevar> { 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:

gamevar TEMP 0 0
onevent EVENT_LOADACTOR
  setvar TEMP 0
  whilevarvarn TEMP NUMSECTORS
  {
    setsector[TEMP].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
}

Commands with an additional "var" suffix take gamevars rather than constants or defined labels for their inputs. As an alternate short form, "varvar" can be dropped from these commands; for example ife serves an an alias for ifvarvare.