Jump to content
Sign in to follow this  
dmarkwick

Variable scope question.

Recommended Posts

If I set a variable, "_thisBoolean", to "true", then execVM a script, can I access this variable?

I need a non-global variable that I can access from other scripts.

Share this post


Link to post
Share on other sites

No, but you can pass variables to scripts, e.g.

nil = [_thisBoolean] execVM "script.sqf"

_thisBoolean can be accessed by _this select 0 in the script then, however it is just a copy of the variable and nothing else.

Any particular reason why you can't use a global variable instead?

Share this post


Link to post
Share on other sites
No, but you can pass variables to scripts, e.g.

nil = [_thisBoolean] execVM "script.sqf"

_thisBoolean can be accessed by _this select 0 in the script then, however it is just a copy of the variable and nothing else.

Any particular reason why you can't use a global variable instead?

I know about the passing parameters, but I need several scripts to have access to, and affect, various non-global variables. The addon works on a per-unit basis so a global variable will just get abused :)

Share this post


Link to post
Share on other sites

Variable scope is sometimes unclear in ArmA. If you post some code it will be easier to help.

Share this post


Link to post
Share on other sites

As you say it's on a per-unit basis and global variables are useless there (i see why), what about writing those variables into the units variablespace with setVariable?

Share this post


Link to post
Share on other sites

Yeah, I'd use setVariable and getVariable then, too.

However in MP, those are local to the client they were set on, so you'd probably need a workaround for that.

But still I think this is what you're looking for.

Share this post


Link to post
Share on other sites
Yeah, I'd use setVariable and getVariable then, too.

However in MP, those are local to the client they were set on, so you'd probably need a workaround for that.

But still I think this is what you're looking for.

They are not local if you make them global :)

http://community.bistudio.com/wiki/setVariable_%28VBS2%29

(ArmA2 compatible)

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
Sign in to follow this  

×