barbolani 198 Posted July 25, 2014 Hello, to make a cache of garrison units, when player conquer a base I use this: server setVariable ["nameofbase",[]];//empty, no garrison as you conquered recently but when I make this: _info = server getVariable "nameofbase"; _garrison = _info select 0; hint format ["%1:%2","nameofbase",count _garrison]; instead of 0 I receive scalar..... only in cases when this empty array is with another arrays, like, for example: _data = [[],true]; server setVariable ["nameofbase",_data]; then, when I make this, and count the proper array, I get 0, which is the desired result. Why I am making this, because you may reinforce the base and, when you do, the array will contain the typeOf units, like: server setVariable ["nameofbase",["inftype","inftype","ATman" blabla]; and then, when I want to create them: _info = server GetVariable "nameofbase"; _arrayunits = _info select 0; {createunit of the type _x} forEach _arrayUnits; Hope I explained well... Thanks in advance for the help!!! Share this post Link to post Share on other sites
squeeze 22 Posted July 25, 2014 check if it has anything in it first _mustexit = false; _info = server getVariable "nameofbase"; if(count _info > 0)then { _garrison = _info select 0; hint format ["%1:%2",_info,count _garrison]; }else{ mustexit = true; }; if(mustexit )exitwith{hint"nothing in garrison}; Share this post Link to post Share on other sites
DarkDruid 96 Posted July 25, 2014 I would recommend to check how the script command "setVariable" works: http://community.bistudio.com/wiki/setVariable You get only the part marked by red color back, when you use that "getVariable" command: server setVariable ["nameofbase",["inftype","inftype","ATman" blabla]]; _info = server getVariable "nameofbase";_garrison = _info select 0; hint format ["%1:%2","nameofbase",count _garrison]; instead of 0 I receive scalar..... There is an empty array in the variable "_info" and you try to select the first item of this array. This ends up with undefined variable as far as there is no first item in that array and after that, script command "count" used on this undefined variable can't simply work. This is the reason, why you don't end up with 0. server setVariable ["nameofbase",["inftype","inftype","ATman" blabla];and then, when I want to create them: _info = server GetVariable "nameofbase"; _arrayunits = _info select 0; {createunit of the type _x} forEach _arrayUnits; This won't work either. There is an array of strings in that "_info" variable. You select the first of them and store it in the variable "_arrayunits" and after that, you are trying to use script command "forEach" on this string. The script command "forEach" can be used only with an array. Share this post Link to post Share on other sites
barbolani 198 Posted July 25, 2014 (edited) aaaaaaaaaaaaahhhhhhhhhhh! you are true!!! Yes, my intention is _info being an array of arrays, so it stores on a first array the types, and in other optional arrays, other parameters. My mistake was, when I declared setVariable, I declared and empty array, and what I should have done is to declare an array with an empty array on it, so, when I make _garrison = _info select 0; it picks the empty array, and a count returns 0. WORKING! Thank you all!!! so the correct thing, with just one eement on the base is: server setVariable ["nameofbase",[[]]]; so when I call it: _info = server getVariable "nameofbase"; _garrison = _info select 0; hint format ["%1", count _garrison]; returns happily a 0 :) Edited July 25, 2014 by barbolani Share this post Link to post Share on other sites