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 77: Line 77:
</syntaxhighlight>
</syntaxhighlight>


Now, to wrap these fields into a single variable, we could use a Nasal hash. Consider the following empty hash:
Now, to wrap these fields into a single variable that serves as the container for other variables, we could use a Nasal hash. Consider the following empty hash:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
Line 98: Line 98:
* bearing
* bearing


Now, to access any of these fields, we would use the "dot notation" by first specifying the name of the enclosing context (which is really just a fancy word for the name of the hash) and the name of the field we are interested in. You could read this as: LOCATION.FIELD (i.e. get FIELD out of location).
Now, to access any of these fields, we would use the "dot notation" by first specifying the name of the enclosing context (which is really just a fancy word for the name of the hash) and the name of the field we are interested in:


<syntaxhighlight lang="php">
<syntaxhighlight lang="php">
Line 110: Line 110:
print ( waypoint.bearing );
print ( waypoint.bearing );
</syntaxhighlight>
</syntaxhighlight>
So, the hash represents the surrounding environment (i.e. context or "namespace") in which these symbols are valid. For more information on namespaces, please see [[Namespaces and Methods]].


Now, to make this is a little more interesting and to show what's happening, we are going to change the value of each field:
Now, to make this is a little more interesting and to show what's happening, we are going to change the value of each field:

Navigation menu