fusion13 11 Posted February 8, 2014 Hello, can anyone explain to me how, setVariable works I have tried to use it and I had no luck, I did it for that it house1 setVariable ["bought", 1, true]; but I noticed that makes the houses var 1, is there a way to make it so that it is global? Thanks, Fusion :dancehead: Share this post Link to post Share on other sites
Zenophon 110 Posted February 8, 2014 Variables are abstracted such that they exist in 'namespaces'. They do not just point to a memory location that you can access. What we commonly call 'global variables' are variables existing in the mission namespace. There is a namespace for every object that exists in game and for your profile (that is how VAS saves data persistently). When you create a variable without setVariable, the engine defaults to the mission namespace or a local namespace. For example: Test = 3; // this is now global for the mission _test = 2; // this is local for the function executing Then, when you retrieve the value of a variable, the engine makes the same assumptions. For example: hint str Test; // prints 3 from anywhere hint str _test; // prints 2 only from the function By using setVariable, you can tell the engine which namespace exactly you want. You must then use getVariable to specify the correct namespace to retrieve from. For setVariable, making the value public (true as the last argument) does not change the namespace where it is stored, but updates the local namespace for all other machines on the network. Thus, another machine can request the same variable from the same namespace and get the same value. If you had put false there, the other machine would read an old value or no value at all. http://community.bistudio.com/wiki/setVariable http://community.bistudio.com/wiki/getVariable http://community.bistudio.com/wiki/missionNamespace So, in your example, the object called house1 now has a variable with value 1 stored at variable referenced by 'bought', and this change its namespace has been broadcast to all other machines. To get this value, you would use: house1 getVariable "bought"; // returns 1 The strength of this system is that you can now keep track of arbitrary values for all objects in an almost object-oriented way. Otherwise, you would have to create some sort of name-value pair data structure to store the 'bought' value for dozens of houses. The weakness of this system is that it obfuscates your data structure into invisible namespace pools. It is critical to have good documentation and standards to use set/get variable on large scale and have maintainable code. Share this post Link to post Share on other sites
fight9 14 Posted February 8, 2014 Wow, good explanation. Thank you. Share this post Link to post Share on other sites