A question for the code-people:
Is there any difference in how the game-engine handles mission_foo and local_foo variables? E.g. are the local_foo variables perhaps automaticly reset on leaving the current system? Or anything else?
Or can they be used pretty much interchangeably?
mission_ and local_ variables
Moderators: winston, another_commander
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
The local variables are tied to a specific script name/mission title.¹ That is, they are local to the script, not to the system. (This is a programmerese usage of “local”.) In contrast, mission variables are global, i.e. all scripts can access the same set of mission variables. As I understand it, locals were introduced because people’s copy & pasted scripts were reusing mission variables elsewhere, which caused problems; if you’re not trying to share data between different scripts, you should probably be using locals.
¹ In script.plist, these are the keys of the dictionary containing the scripts, such as “thargoid_plans” and “constrictor_hunt” in the built-in script. I don’t know about other scripting contexts. JavaScripts can set their name explicitly, but don’t need to use local_foo anyway.
Side note: I’m reserving the name “!metadata!” for future use. If you intended to write a script called “!metadata!”, try thinking of a name that makes sense.
¹ In script.plist, these are the keys of the dictionary containing the scripts, such as “thargoid_plans” and “constrictor_hunt” in the built-in script. I don’t know about other scripting contexts. JavaScripts can set their name explicitly, but don’t need to use local_foo anyway.
Side note: I’m reserving the name “!metadata!” for future use. If you intended to write a script called “!metadata!”, try thinking of a name that makes sense.
E-mail: [email protected]
-
- Quite Grand Sub-Admiral
- Posts: 364
- Joined: Tue Aug 17, 2004 7:05 am
- Location: Orange, NSW, Australia
The other difference is that mission variables are written to the save game files, whereas local ones are not.
Local variables are tied to specific scripts, are all undefined when the game loads, and keep their values only as long as the game is running.
I cannot recall if they are all removed when a saved game is loaded or not.
Local variables are tied to specific scripts, are all undefined when the game loads, and keep their values only as long as the game is running.
I cannot recall if they are all removed when a saved game is loaded or not.
Regards,
David Taylor.
David Taylor.
- Arexack_Heretic
- Dangerous Subversive Element
- Posts: 1876
- Joined: Tue Jun 07, 2005 7:32 pm
- Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
- Contact:
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Ahh, yes. That one’s worth keeping in mind. :-)dajt wrote:The other difference is that mission variables are written to the save game files, whereas local ones are not.
E-mail: [email protected]
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
Thanks, all, for the answers!
I am completely satisfied.
I also find the distiction between writing or not-writing in the save-file very interesting. I think intuitively I have used my variables accordingly when scripting. I use local_variables in instances where there is no need (and I don't want) to write something in the savefile. But as I didn't know that they are not saved anyway I always reset them when I don't need them anymore. Perhaps in future I can spare me that line of code in the script.
I am completely satisfied.
I also find the distiction between writing or not-writing in the save-file very interesting. I think intuitively I have used my variables accordingly when scripting. I use local_variables in instances where there is no need (and I don't want) to write something in the savefile. But as I didn't know that they are not saved anyway I always reset them when I don't need them anymore. Perhaps in future I can spare me that line of code in the script.