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

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
mNo edit summary
Line 375: Line 375:
var waypoint5 = {parents:[waypoint1] };
var waypoint5 = {parents:[waypoint1] };
</syntaxhighlight>
</syntaxhighlight>
or using a vector for each object:
<syntaxhighlight lang="php">
var waypoint = {number:1,altitude:2,distance:3,angle:4,length:5,ID:6,bearing:7};
var waypoints = [0,0,0,0,0]; # initialize the vector to set its size
var waypoints[0] = {parents:[waypoint] };
var waypoints[1] = {parents:[waypoint] };
var waypoints[2] = {parents:[waypoint] };
var waypoints[3] = {parents:[waypoint] };
var waypoints[4] = {parents:[waypoint] };
</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 waypoints = [0,0,0,0,0]; # initialize the vector to set its size
foreach(var wpt; waypoints) {
wpt = {parents:[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