Jump to content

Recommended Posts

 

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

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 by -Varan
One can't access a single function in an external script in sqf like in real programming languages
  • Like 1

Share this post


Link to post
Share on other sites

@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!


getVariable
missionNameSpace

  • Like 2

Share this post


Link to post
Share on other sites

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

@Minal,

missionNameSpace setVariable ["variable", 4584]; //in init

myVar=missionNameSpace getVariable ["variable", 0];
systemChat format ["%1", myVar]; // to hint

Have fun!

  • Like 2

Share this post


Link to post
Share on other sites

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.

  • Like 1

Share this post


Link to post
Share on other sites

@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!

  • Like 1
  • Haha 2

Share this post


Link to post
Share on other sites

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

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

  • Like 1

Share this post


Link to post
Share on other sites
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.

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×