Linker Split 0 Posted February 5, 2015 (edited) Hi guys! I'm creating a script that should save objects and their properties into an array dinamically (looping every 5 seconds) that must be used into another script. Basically, arguments are: _obj = a tent; _items = an empty array to be filled with objects; _arrItems: all the items the tent is already carrying; _nmbr = a number used to save and pick the correct tent from a function (which is out of interest here); _numToCheck = as above; _uniID = as above. The following two function are compiled within the init.sqf. I've made a function EPfn_saveInventory which must loop and check for new objects inside the tent: EPfn_saveInventory = { private["_obj","_items","_arrItems","_count","_i"]; _obj = _this select 0; _items = _this select 1; _arrItems = items _obj; _count = count _arrItems; _i = 0; if (_count == 0) exitWith {diag_log "NO OBJECTS INTO THE ARRITEMS"}; while {_i < _count} do { //private["_i"]; diag_log format["EPfn_saveInventory COUNT IS %1, _I is %2, ITEMS ARE %3",_count,_i,_arrItems]; _item = (_arrItems select _i); _type = typeOf _item; _Dam = damage _item; _qty = quantity _item; _newArr = [_type ,_Dam,_qty]; _items set [_i,_newArr]; sleep 1; _i = _i+1; }; diag_log format["EPfn_saveInventory ITEMS ARE %1",_items]; }; Passed arguments _obj, _items are from a function that (get looped by another script) which is EPfn_saveTentData. This function get looped because it must sve all the data of the tents. EPfn_saveTentData = { private ["_obj","_nmbr","_numToCheck","_uniID"]; _obj = _this select 0; _nmbr = _this select 1; _numToCheck = _this select 2; _uniID = _this select 3; _dam = damage _obj; _dir = direction _obj; _items = []; [b][color="#FF0000"][_obj,_items] spawn EPfn_saveInventory;[/color][/b] _type = typeOf _obj; _xPos = (getPosASL _obj) select 0; _yPos = (getPosASL _obj) select 1; _zPos = (getPosASL _obj) select 2; _globo = _obj getVariable ["globalID",[]]; _stringToPass = format["%1,%2,%3,%4,%5,%6,%7,%8,%9,%10",_uniID,_type,_nmbr,_numToCheck,_xPos,_yPos,_zPos,_dir,_dam,_items]; profileNameSpace setVariable [format["TENTOBJ%1",_nmbr],_stringToPass]; saveProfileNameSpace; }; All the data of the tents are saved (position, damage, type, ID etc.) but I can't get the objects that a player puts inside the tent. Indeed, the _stringToPass (which get saved like this: [TentMedium_Pitched,16,31,4708,10091.2,338.881,0,0,[]] in the profileNameSpace) has an empty [] at the end while there should be something like ["M16A2",0,0]. It doesn't see what is passed via EPfn_saveInventory (which instead gives me the correct data, I checked via diag_log). What am I doing wrong? #EDIT I show you the RPT: 23:23:15 "EPfn_saveInventory COUNT IS 1, _I is 0, ITEMS ARE [Medical_Splint:2:30995]"23:23:15 "EPfn_saveInventory ITEMS ARE [["Consumable_Chemlight_Blue",0.769509,0]]" 23:23:17 "itemsInCargo FROM EPfn_saveTentData IS []" 23:23:17 "GLOBALARRAY FROM EPfn_saveTentData IS ["TentMedium_Pitched",16,31,4708,10091.2,338.881,0,0,[]]" First line of EPfn_saveInventory is executed (correct) Second line of EPfn_saveInventory is executed (correct) which means that the code inside is correct Third line of EPfn_saveTentData is executed but not correct: _items is still empty [] Fourth line of EPfn_saveTentData is executed but not correct, cause last object of the big array should contain ["Consumable_Chemlight_Blue",0.769509,0] Edited February 5, 2015 by Linker Split Share this post Link to post Share on other sites
Linker Split 0 Posted February 6, 2015 (edited) Ok, I got it working. I modifed the function to be like this: EPfn_saveInventory = { private["_obj","_items","_arrItems","_count","_i"]; _obj = _this select 0; _items = []; _arrItems = items _obj; _count = count _arrItems; if (_count == 0) then { _items =[]; diag_log "NO OBJECTS INTO THE ARRITEMS"; } else { diag_log "THERE ARE OBJECTS INTO THE ARRITEMS"; for "_i" from 0 to (_count -1) do { _item = (_arrItems select _i); _type = typeOf _item; _Dam = damage _item; _qty = quantity _item; _newArr = [_type,_Dam,_qty]; _items set [_i,_newArr]; }; diag_log format["EPfn_saveInventory ITEMS ARE %1",_items]; }; _items }; And it's called with this line: _items = [_obj] call EPfn_saveInventory; . Now what I don't get is why is it saving string like this? [[color="#FF0000"]""[/color]Headtorch_Grey[color="#FF0000"]""[/color],0.428685,0],[[color="#FF0000"]""[/color]Crafting_MetalWire[color="#FF0000"]""[/color],0.536768,0] Edited February 6, 2015 by Linker Split Share this post Link to post Share on other sites
f2k sel 164 Posted February 6, 2015 Sorry can't really help but what is _qty = quantity _item; I thought it may be count but then _item would have to be an array wouldn't it? Share this post Link to post Share on other sites
fight9 14 Posted February 6, 2015 I noticed that too but forgot to post it. Also, what are these inventory items?They cant be soldier inventory stuff because typeOf & damage wouldnt work on them. Are they cfgVehicle objects? Share this post Link to post Share on other sites
f2k sel 164 Posted February 7, 2015 I noticed that too but forgot to post it.Also, what are these inventory items?They cant be soldier inventory stuff because typeOf & damage wouldnt work on them. Are they cfgVehicle objects? I wasn't sure myself, I tried passing an actual item but nothing happened. _count = count _arrItems; // returned 0 I then tried with a man and it returned 1 the script then crashes saying something about a string error caused by this line _type = typeOf _item; I did mess about changing a few thing but could never get the double quotes. Share this post Link to post Share on other sites