Howto:Start using vectors and hashes in Nasal: Difference between revisions

Jump to navigation Jump to search
m
→‎A hash based version (recommended): foreach index expression not an lvalue
mNo edit summary
m (→‎A hash based version (recommended): foreach index expression not an lvalue)
Line 404: Line 404:
var waypoints[4] = new_waypoint();
var waypoints[4] = new_waypoint();
</syntaxhighlight>
</syntaxhighlight>
or even, using a vector and a foreach loop:
<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 waypoints = [0,0,0,0,0]; # initialize the vector to set its size
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.

Navigation menu