Jump to content
Sign in to follow this  

Recommended Posts

I have used many commands in arma2, but one I haven't used before is setVariable and getVariable. How do these actually work?

I don't find the description in the BIKI deep enough, and I still don't get how they work. When it says "Set variable to given value in the variable space of given element", what is the variable space? Is an array automatically created by the command that is associated with the object, that contains all the setVariable values? Or is it something else? I still can't see clear on how this works.

I noticed alot of mission editors are using this method as shortcuts to PV variables when assigning object-specific variables (object as in unit, or vehicle) but what are the up and down sides of these methods, and how do they operate?

I would grateful as if someone was to inform me on this and clear things up a bit, even a more descriptive link would do.

Edited by Double Doppler

Share this post


Link to post
Share on other sites

You can use common objects to server and clients, like logicgame named "server", to store variables and their values.

For example, you can use them for broadcast an objective completed:

In trigger "on act" field:

server setvariable ["var_obj1_done",true,true]

And in another trigger "condition" field:

(server getVariable "var_obj1_done")

and "on act":

_handle = [objNull, ObjNull, TskObj1, "Succeeded"] execVM "CA\Modules\MP\data\scriptCommands\taskHint.sqf"

The variable will be automatically broadcasted to JIP players too.

Hope this will help you ;)

Share this post


Link to post
Share on other sites

They are just variables stored into the object instead of to the mission's namespace (aka global variables). Even without the handy sync feature they are more convenient to keep unit/object specific data.

unit1 setvariable ["name","John"];

unit2 setvariable ["name","Mike"];

Then you can just do

_name = _unit getvariable "name";

to retrieve the name of an unit, which would be more complicated with global array variable.

Share this post


Link to post
Share on other sites

As Shuko pointed out, they are variables that can be stored in objects memory space. Its a very convenient thing, because it gives you a way to pass/update/check values in multiple scripts without using a global variable, or having to create an array of global variables to check for every specific object in question.

Share this post


Link to post
Share on other sites

So if I'm right, SetVariable in reality is an array containing nested arrays, with the values linked to the units name? (technically speaking).

E.g.

array = [["player",["variable1",value]],["antagonist",["variable1",value]]];

And I'm guessing you use "GetVariable" to retrieve the variable value (performs a loop on that array and finds the name string matching the one requesting, then returns the value).

Correct me if I'm wrong.

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  

×