For: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Documentation of the "for" CON keyword.
 
Add note about conditional evaluation
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
'''for''' <[[gamevar]]> <iterator> { code to execute }<br>
'''for''' <gamevar> <function> { [...] }<br>
'''for''' <[[gamevar]]> <iterator> <num> { code to execute }
'''for''' <gamevar> <function> <value> { [...] }


Executes the code in the curly braces for every instance of the iterator specified, and <[[gamevar]]> stores the sprite/sector/wall/etc found in the current iteration. For example, setting <iterator> to '''allsprites''' will execute the code for every sprite in-game, and the var specified in <[[gamevar]]> will be set to the sprite number of the current sprite it's on.
Executes the code in the curly braces for every instance of the function specified, and <[[gamevar]]> stores the sprite/sector/wall/etc found in the current function.


Iterator types:
For example, setting <function> to '''allsprites''' will execute the code for every sprite in-game, and the var specified in <[[gamevar]]> will be set to the sprite number of the current sprite it's on.
:'''allsprites''' - All actors/sprites in-game.
 
:'''allsectors''' - All sectors in the map.
== Functions ==
:'''allwalls''' - All walls in the map.
 
:'''activelights''' - All active polymer lights.
{| {{prettytable}}
:'''drawnsprites''' - Only the sprites currently being drawn.
| '''allsprites''' || All actors/sprites in-game.
:'''spritesofsector <sector num>''' - All sprites in the given sector.
|-
:'''spritesofstatus <statnum>''' - All sprites with the given [[statnum]].
| '''allsectors''' || All sectors in the map.
:'''wallsofsector <sector num>''' - The walls of the given sector.
|-
:'''loopofwall <wall num>''' - All walls in the same loop of the given wall.
| '''allwalls''' || All walls in the map.
:'''range <num>''' - A range from 0 to the number specified.
|-
| '''activelights'''<br />'''lights''' || All active polymer lights.
|-
| '''drawnsprites''' || Only the sprites currently being drawn.
|-
| '''spritesofsector'''<sectnum><br /> '''sprofsec'''<sectnum> || All sprites in the given sector.
|-
| '''spritesofstatus''' <statnum><br />'''sprofstat''' <statnum> || All sprites with the given [[statnum]].
|-
| '''wallsofsector''' <sectnum><br />'''walofsec''' <sectnum> || The walls of the given sector.
|-
| '''loopofwall''' <wall num> || All walls in the same loop of the given wall.
|-
| '''range''' <num> || A range from 0 to the number specified.
|}
 
Unlike other loop forms, the conditional statement is ''not'' re-evaluated each iteration. For example, the following loop will log 1 through 10:
 
var i
var j 10
for i range j {
    add i 1 // only affects current iteration; log 1..10 instead of 0..9
    sub j 1 // same as above; effectively does nothing in this example
    al i
}


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

Latest revision as of 08:12, 15 July 2020

for <gamevar> <function> { [...] }
for <gamevar> <function> <value> { [...] }

Executes the code in the curly braces for every instance of the function specified, and <gamevar> stores the sprite/sector/wall/etc found in the current function.

For example, setting <function> to allsprites will execute the code for every sprite in-game, and the var specified in <gamevar> will be set to the sprite number of the current sprite it's on.

Functions

allsprites All actors/sprites in-game.
allsectors All sectors in the map.
allwalls All walls in the map.
activelights
lights
All active polymer lights.
drawnsprites Only the sprites currently being drawn.
spritesofsector<sectnum>
sprofsec<sectnum>
All sprites in the given sector.
spritesofstatus <statnum>
sprofstat <statnum>
All sprites with the given statnum.
wallsofsector <sectnum>
walofsec <sectnum>
The walls of the given sector.
loopofwall <wall num> All walls in the same loop of the given wall.
range <num> A range from 0 to the number specified.

Unlike other loop forms, the conditional statement is not re-evaluated each iteration. For example, the following loop will log 1 through 10:

var i
var j 10
for i range j {
    add i 1 // only affects current iteration; log 1..10 instead of 0..9
    sub j 1 // same as above; effectively does nothing in this example
    al i
}