Smoerble 11 Posted October 10, 2014 (edited) Hello all. I want to use a variable in different sqf files. init.sqf: smo_ammoBoxLoadout = [""]; test1.sqf: player globalChat format["test: %1", count smo_ammoBoxLoadout]; error message: error in line 52: _a = count smo_ammoBoxLoadout; Error Undefined variable in expression: smo_ammoboxloadout I also tried to define the variable in init.sqf like this: this setVariable ["smo_ammoBoxLoadout",["test"], false]; Anyone has an idea please? Edited October 10, 2014 by Smoerble Share this post Link to post Share on other sites
A.Cyprus 16 Posted October 10, 2014 (edited) --- removed in deference to better response below --- Edited October 10, 2014 by ACyprus Share this post Link to post Share on other sites
Belbo 461 Posted October 10, 2014 Usually global variables are visible to all scripts that are being executed after the variable is defined. So if you define a variable globally (like smo_ammoBoxLoadout; local variables have an underscore in front of them: _ammoBoxLoadout), it should already be available to your test1.sqf. But you have to call your test1.sqf after your init.sqf, or after your definition of smo_ammoBoxLoadout in the init.sqf. So smo_ammoBoxLoadout = ["1"]; [] execVM "test1.sqf"; should work. If you're already doing it like that, the empty entry may be a problem. But that's just a guess. Share this post Link to post Share on other sites
tinter 184 Posted October 10, 2014 If timing of script execution can wait, putting waitUntil {!isNil "smo_ammoBoxLoadout"}; in your script will suspend it until the variable is defined. Remember than waitUntil can only be used in scheduled enviroment, and for isNil the variable you're looking for should always be a string, or it will try to read the variable. Share this post Link to post Share on other sites
Smoerble 11 Posted October 10, 2014 @Tinter: that helped, many thanks! Share this post Link to post Share on other sites