allVariables – Talk

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Global object and namespace quirks)
m (Text replacement - "<code>" to "<code style="display: block">")
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
I don't really play around on the dev build so I'm a little confused with this command. Does it return all variables or only the ones created with [[setVariable]]?
:Let's assume that you're using global variables (since I'm not sure if local variables are actually in any namespace). [[setVariable]] is simply a handy means of setting a variable, so it would return the variables in your first and second example as well as if you had used <code style="display: block">missionNamespace setVariable ["myVariable",0]</code>. --[[User:SilentSpike|SilentSpike]] ([[User talk:SilentSpike|talk]]) 21:20, 12 December 2014 (CET)
for example:
<code>_myVariable = 0;
'''//same as'''
with missionNamespace do
{
_myVariable = 0;
};</code>
I guess I don't understand how the different namespaces work either. Would this command return ["_myVariable"] in both cases? - [[User:DreadedEntity|DreadedEntity]] ([[User talk:DreadedEntity|talk]]) 20:50, 12 December 2014 (CET)
:Let's assume that you're using global variables (since I'm not sure if local variables are actually in any namespace). [[setVariable]] is simply a handy means of setting a variable, so it would return the variables in your first and second example as well as if you had used <code>missionNamespace setVariable ["myVariable",0]</code>. --[[User:SilentSpike|SilentSpike]] ([[User talk:SilentSpike|talk]]) 21:20, 12 December 2014 (CET)
::Creating a global variable automatically sets it into the missionNamespace:
::Creating a global variable automatically sets it into the missionNamespace:
::<code><nowiki>someVar = "Hello, world";
::<code style="display: block"><nowiki>someVar = "Hello, world";
hintSilent format ["%1", missionNamespace getVariable "someVar"]; //result: "Hello, world"</nowiki></code>
hintSilent format ["%1", missionNamespace getVariable "someVar"]; //result: "Hello, world"</nowiki></code>
::So there's no need for that. You can overwrite variables in the namespaces, just as you can overwrite global variables by reassigning them. But if you create objects which are global by default (like triggers), you can overwrite their reference (as variables are called by reference), but this will not overwrite the object itself:
::So there's no need for that. You can overwrite variables in the namespaces, just as you can overwrite global variables by reassigning them. But if you create objects which are global by default (like triggers), you can overwrite their reference (as variables are called by reference), but this will not overwrite the object itself:
::<code><nowiki>myFancyTrigger = createTrigger ["EmptyDetector", getPosATL player];
::<code style="display: block"><nowiki>myFancyTrigger = createTrigger ["EmptyDetector", getPosATL player];
_trigger = createTrigger ["EmptyDetector", getPosATL player];
_trigger = createTrigger ["EmptyDetector", getPosATL player];
missionNamespace setVariable ["myFancyTrigger", _trigger];
missionNamespace setVariable ["myFancyTrigger", _trigger];
</nowiki></code>
</nowiki></code>
::In fact, after this, there will still be both triggers, though the missionNamespace only knows the last one. --[[User:Heeeere's Johnny!|Johnny]]
::In fact, after this, there will still be both triggers, though the missionNamespace only knows the last one. The same thing would happen if you assigned the created trigger to a global variable and overwrite that. --[[User:Heeeere's Johnny!|Johnny]]

Latest revision as of 12:53, 11 January 2023

Let's assume that you're using global variables (since I'm not sure if local variables are actually in any namespace). setVariable is simply a handy means of setting a variable, so it would return the variables in your first and second example as well as if you had used missionNamespace setVariable ["myVariable",0]. --SilentSpike (talk) 21:20, 12 December 2014 (CET)
Creating a global variable automatically sets it into the missionNamespace:
someVar = "Hello, world"; hintSilent format ["%1", missionNamespace getVariable "someVar"]; //result: "Hello, world"
So there's no need for that. You can overwrite variables in the namespaces, just as you can overwrite global variables by reassigning them. But if you create objects which are global by default (like triggers), you can overwrite their reference (as variables are called by reference), but this will not overwrite the object itself:
myFancyTrigger = createTrigger ["EmptyDetector", getPosATL player]; _trigger = createTrigger ["EmptyDetector", getPosATL player]; missionNamespace setVariable ["myFancyTrigger", _trigger];
In fact, after this, there will still be both triggers, though the missionNamespace only knows the last one. The same thing would happen if you assigned the created trigger to a global variable and overwrite that. --Johnny