Andy Ross wrote: > Stewart Andreason wrote: > >> Is there a preference for how variables are declared and used in nasal? >> between the global type: >> var some_name = 0; >> which can be accessed and changed from any function, >> > > That's a Nasal variable. It's not "global" in the sense that all > users will see the same value for "name". It's part of the namespace > of the executing function (which might be the whole file), and is > visible only to the current function, and other "func" expressions > assigned during that execution. > > Thanks for the clarification Andy, I meant global to the nasal file, and available only to the functions defined within. >> and using the nodes >> var name = >> props.globals.getNode("/sim/model/aircraftName/someDirectory/name",1); >> and accessing with .getValue and .setValue. >> > > That's *also* a Nasal variable, but it holds a reference to a property > node instead of an actual value. Interestingly, the property node, > unlike the variable above, *is* a global thing (i.e. every part of > FlightGear sees the same node for /sim/model/.../name). > > The advantage to Nasal-space data is that it's fast and simple. If > the only thing that will care about the value is your script, they are > good choices. > >
Right. When writing my nasal scripts, I imitated other available examples in programming style. I'm just questioning if it is necessary, or faster mostly, to define a "local" variable in a function for multiple accesses. func { var temp1 = globalVar.getValue(); if (temp1 > 0.5) { # typical usage seen var x1 = temp1 + (temp1 * 4); # for a more intense example etc. or if it is more for filesize, and easier to read. It would seem, if temp1 only gets accessed once past declaration, then it would not be efficient. If accessing temp1 _is_ faster than .getValue, then at 2 or 3 accesses, I imagine it becomes faster to do the above? Thanks, Stewart ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel