20,741
edits
m (→A hash based version (recommended): http://forum.flightgear.org/viewtopic.php?f=71&t=23204&p=211634#p211629) |
m (→A hash based version (recommended): http://forum.flightgear.org/viewtopic.php?f=71&t=23204&p=211634#p211629) |
||
Line 441: | Line 441: | ||
waypoints[i] = new_waypoint(); | waypoints[i] = new_waypoint(); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Instead of the forindex loop, we can also use a foreach loop to directly access the stored element, without having to use an index: | |||
<syntaxhighlight lang="php"> | |||
var waypoint = {number:1,altitude:2,distance:3,angle:4,length:5,ID:6,bearing:7}; | |||
var new_waypoint = func {return {parents:[waypoint] };} | |||
var NUM_ELEMENTS = 5; | |||
var waypoints = []; | |||
setsize(waypoints, NUM_ELEMENTS); | |||
foreach(var wpt; waypoints) | |||
wpt = new_waypoint(); | |||
</syntaxhighlight> | |||
Once we start using a hash as a template for other hashes using the "parents" vector, we are actually creating a class that is copied to each new hash. This new copy of the class is called an "object" after creation. | Once we start using a hash as a template for other hashes using the "parents" vector, we are actually creating a class that is copied to each new hash. This new copy of the class is called an "object" after creation. |