Minal 7 Posted May 13, 2020 Good afternoon all! I am here today because I meet a problem ... Indeed I do not know how to retrieve in a script the content of a variable that was created in another script. In other words I have a script 1 which has a variable _chose and in script 2 I want to recover this variable _chose. Thank you for reading my few lines! and I hope you can help me ... Good bye ! Share this post Link to post Share on other sites
-Varan 1 Posted May 13, 2020 (edited) Just script a "set function" in script 1 which returns _chose and call the function from script 2 AFAIK it is necessary to use setVariable to declare _chose in script 1. Just use a smart namespace - if the varable applies to the player use namespace player player setVariable ["_chose", 1]; In script 2 read the variable with _chose = player getVariable "_chose"; Edited May 13, 2020 by -Varan One can't access a single function in an external script in sqf like in real programming languages 1 Share this post Link to post Share on other sites
wogz187 1086 Posted May 13, 2020 @Minal Post the script so we can see. Generally speaking to record a variable for other scripts to read you would, missionNameSpace setVariable ["my_var", true]; This is a global variable available to other scripts. To read it, current_state=missionNameSpace getVariable ["my_var", false]; Have fun!getVariablemissionNameSpace 2 Share this post Link to post Share on other sites
Minal 7 Posted May 13, 2020 Hi thx all, in my init.sqf i have _Variable = 4584; et dans mon script.sqf I want to hint _Variable and i don't how I can do. Can you help me please ? @wogz187 Share this post Link to post Share on other sites
wogz187 1086 Posted May 13, 2020 @Minal, missionNameSpace setVariable ["variable", 4584]; //in init myVar=missionNameSpace getVariable ["variable", 0]; systemChat format ["%1", myVar]; // to hint Have fun! 2 Share this post Link to post Share on other sites
target_practice 163 Posted May 13, 2020 Or just assign as a global variable by omitting the underscore, which does exactly the same thing in this case if I'm not mistaken. 1 Share this post Link to post Share on other sites
wogz187 1086 Posted May 13, 2020 @target_practice, Quote ... a global variable by omitting the underscore, which does exactly the same thing in this case if I'm not mistaken. The big difference between global variables and missionNameSpace/unit variables is when using the latter @Dedmen won't make fun of (me). Have fun! 1 2 Share this post Link to post Share on other sites
target_practice 163 Posted May 13, 2020 It also has the difference of being slower and harder to read, so there really is no real reason for it. Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted May 14, 2020 Local variables will only exist inside the scope(and child scopes) you created them. You can pass the local variable to another script as parameter or, as mentioned above simply use a global variable (which might not be what you want depending on what you're trying to achieve). You can also use setVariable/getVariable and use objects/units/groups etc. to save and retrieve those variables. I'd only use global variables as a last resort, since they can be overridden by other scripts/mods using the same variable names. Cheers 1 Share this post Link to post Share on other sites
Dedmen 2714 Posted May 14, 2020 2 hours ago, Grumpy Old Man said: since they can be overridden by other scripts/mods using the same variable names. Which is why you use your own unique tag for every global variable. 2 Share this post Link to post Share on other sites