Rebitaay 13 Posted March 16, 2017 Hi all, I'm re-doing a script for a mission I'm making. It detects X out of 10 caches on the map, X being the value of the mission parameter "CacheCount" (2, in this case). It's meant to detect when all detected caches are dead, and then end the mission, but it gives me this error, which comes from the last line. Code: private ["_array","_findCaches"]; _caches = []; _findCaches = for "_i" from 1 to ("CacheCount" call BIS_fnc_getParamValue) do {_caches pushBack format["Cache%1", _i]}; sleep 1; while {({alive _x} count _caches) == 0} do {"End1" call BIS_fnc_endMission}; I'm guessing the issue is that "pushBack" in line 3 creates ["Cache1","Cache2"] instead of [Cache1,Cache2]. So is there any way to pushBack an object name, or turn the array strings into object names? I can't find anything useful through google. Any advice would be appreciated! Share this post Link to post Share on other sites
Rebitaay 13 Posted March 16, 2017 Okay, I've gotten it to "pushBack" object names instead of strings, but I've got another error. "Error alive: Type Text, expected Object" This is my current code: private ["_array","_findCaches"]; _caches = []; _findCaches = for "_i" from 1 to ("CacheCount" call BIS_fnc_getParamValue) do {_caches pushBack formatText ["Cache%1", + _i]}; sleep 1; waitUntil {({alive _x} count _caches) == 0}; // I realised "While" might spam the ending sleep 3; "End1" call BIS_fnc_endMission; I'm guessing it has something to do with the _caches array once again because it works just fine if I use: count [Cache1,Cache2,Cache3,Cache4,Cache5,Cache6] instead of "count _caches"... Share this post Link to post Share on other sites
mrcurry 258 Posted March 16, 2017 Assuming all caches exists at the time of execution change _caches pushBack formatText ["Cache%1", + _i] To _caches pushBack call compile format ["Cache%1", _i] 1 Share this post Link to post Share on other sites
Rebitaay 13 Posted March 16, 2017 16 minutes ago, mrcurry said: _caches pushBack call compile format ["Cache%1", _i] The script now works after 5 hours of failure. You're a legend. Share this post Link to post Share on other sites
serena 145 Posted March 16, 2017 while {count _caches < _findCaches} do {_caches pushBack "Cache" + str count _caches}; Share this post Link to post Share on other sites
mrcurry 258 Posted March 16, 2017 With your current setup the caches will be selected in the same order every time. If you want to randomize things a bit you can use this instead: private _allCaches = [Cache1, Cache2, Cache3, Cache4, Cache5, Cache6]; //Fill this with all caches. private _cacheCount = "CacheCount" call BIS_fnc_getParamValue; private _caches = []; for "_i" from 1 to _cacheCount do { _caches pushBack (_allCaches deleteAt floor random _allCaches); }; sleep 1; waitUntil {({alive _x} count _caches) == 0}; sleep 3; "End1" call BIS_fnc_endMission; Share this post Link to post Share on other sites
Rebitaay 13 Posted March 16, 2017 @serena @mrcurry Thank you both for your great codes, but I already have exactly what I need. I always like knowing multiple ways of scripting something though, so I appreciate it. Share this post Link to post Share on other sites