Naiss 28 Posted December 18, 2014 okey so im using a list box for the inventory and when the player is trying to drop an item that he select from the inventory it needs to call the item array and get the right object that will drop on the ground. i tryed alot of thinks but i just dont know how to do it. Dialog: { _itemAmount = [_x select 0] call RPP_Inventory_Count; _item = lbAdd [1500, format ["%1 (x%2)",_x select 0, _x select 1]]; lbSetData [1500, _item, _x select 1]; } foreach RPP_Inventory Selecton part: if (lbCurSel 1500 == -1) exitWith { systemChat "Please Select an item to drop."; }; _item = RPP_Inventory select (lbCurSel 1500); _name = _item select 0; _amount = round(parseNumber(ctrlText 1400)); Item Array: RPP_Items = [ ["Cash","Cash",1,1,false,0,"Land_money_F"], //The last part here with the land_money_f is the object that i want to drop on the ground ["RepairKit","Repair Kit",75,60,true,10,"item_toolkit"] ]; Share this post Link to post Share on other sites
jshock 513 Posted December 19, 2014 You may find this page useful: https://community.bistudio.com/wiki/Array Share this post Link to post Share on other sites
dreadedentity 278 Posted December 19, 2014 This is really confusing. I'm not sure what you're asking for. Do you want something like this? myArray2 select (myArray1 select myVariable); Share this post Link to post Share on other sites
Larrow 2823 Posted December 19, 2014 (edited) As DE says, what youre asking for is very vague especially without knowing the structure of RPP_Inventory. Im presuming that RPP_Inventory select 0 is the description of an item and that you want to compare this item name to each entry in RPP_Items, when found retrieve the class name for spawning? something like.. if (lbCurSel 1500 == -1) exitWith { systemChat "Please Select an item to drop."; }; _item = RPP_Inventory select (lbCurSel 1500); _name = _item select 0; _amount = round(parseNumber(ctrlText 1400)); _className = ""; { _itemType = _x select 0; if ( _itemType == _item ) exitWith { _className = _x select 6; }; }forEach RPP_Items; createVehicle [ _className, [ getPosATL player, 2, getDir player] call BIS_fnc_relPos, [], 0, "CAN_COLLIDE" ]; If not then you need to provide more information on what your doing. Using the listbox index could provide very problematic depending on how your RPP_Inventory is handled. What if you drop the last of a certain item? This could leave your indexs out of sync with your RPP_Inventory array. _____________________________________ Several other things do not make sense. { _itemAmount = [_x select 0] call RPP_Inventory_Count; _item = lbAdd [1500, format ["%1 (x%2)",_x select 0, _x select 1]]; lbSetData [1500, _item, _x select 1]; } foreach RPP_Inventory Why do you get an item count and never use it? Seeing as your formatting a string which i presume (x%2) is meant to represent this count, surely the line should read _item = lbAdd [1500, format ["%1 (x%2)",_x select 0, _itemAmount]]; but as you do not provide enough information this is purely speculation. Edited December 19, 2014 by Larrow Share this post Link to post Share on other sites
Naiss 28 Posted December 19, 2014 the only problem i got right now is this the _item is giving me an undefined variable for somereason here RPP_Inventory_Drop = { private ["_item","_amount","_itemType","_className","_name"]; if (lbCurSel 1500 == -1) exitWith { systemChat "Please Select an item to drop."; }; _item = RPP_Inventory select (lbCurSel 1500); _name = _item select 0; _amount = round(parseNumber(ctrlText 1400)); _className = ""; { _itemType = _x select 0; if ( _itemType == _item ) exitWith { _className = _x select 6; }; }forEach RPP_Items; createVehicle [ _className, [ getPosATL player, 2, getDir player] call BIS_fnc_relPos, [], 0, "CAN_COLLIDE" ]; }; RPP_Inventory_ItemAdd = { private ["_itemClass","_itemName","_amount"]; _itemClass = _this select 0; _itemName = _this select 1; _amount = _this select 2; RPP_Inventory = RPP_Inventory + [[_itemClass,_itemName,_amount]]; }; //and here is the function when i add stuff into the inventory RPP_buy = { _shopname = _this select 0; _shop = _shopname select (lbCurSel 1500); _cfg = _shop select 0; _class = _shop select 1; _Price = _shop select 2; [_cfg, _class, 1, _shop] call RPP_Inventory_ItemAdd; }; Share this post Link to post Share on other sites
Larrow 2823 Posted December 19, 2014 the only problem i got right now is this the _item is giving me an undefined variable for somereason hereWhere? can you be more specific like the actual error shown on screen or from your RPT.Can you please change your code from your first post, where you fill the listbox, to look like the below. Run your UI up and then paste the contents of you clipboard into code tags in a post. { _itemAmount = [_x select 0] call RPP_Inventory_Count; _item = lbAdd [1500, format ["%1 (x%2)",_x select 0, _x select 1]]; lbSetData [1500, _item, _x select 1]; } foreach RPP_Inventory; copyToClipboard ( str RPP_Inventory ); Share this post Link to post Share on other sites
Naiss 28 Posted December 19, 2014 i changed it to this with the list box now: { lbAdd [1500, format ["%1",_x select 1]]; } foreach RPP_Inventory and i get the error in the drop function: Share this post Link to post Share on other sites
Larrow 2823 Posted December 19, 2014 i changed it to this with the list box now: { lbAdd [1500, format ["%1",_x select 1]]; } foreach RPP_Inventory Ok but can you still add the copyToClipboard line below that and paste the result here so i can get some idea of what RPP_Inventory looks like. Share this post Link to post Share on other sites
Naiss 28 Posted December 19, 2014 this is what i got [["RPP_RepairKit","RepairKit",1]] ---------- Post added at 14:59 ---------- Previous post was at 14:44 ---------- and if i buy let's say another item witch would maybe be medkit then it will look like this: [["RPP_RepairKit","RepairKit",1]], [["RPP_Medkit","Medkit",1]] Share this post Link to post Share on other sites
Larrow 2823 Posted December 19, 2014 Ok so you currently only have one item listed in your listbox? If this is the case then on selecting it lbCurSel should return 0, _item = RPP_Inventory select (lbCurSel 1500); So _item should be ["RPP_RepairKit","RepairKit",1] _name = _item select 0; So name should be "RPP_RepairKit" Is this true? Remove the copyToClipboard line from previous post. Change RPP_Inventory_Drop to look like this RPP_Inventory_Drop = { private ["_item","_amount","_itemType","_className","_name"]; if (lbCurSel 1500 == -1) exitWith { systemChat "Please Select an item to drop."; }; _item = RPP_Inventory select (lbCurSel 1500); copyToClipboard format[ "Index : %1 , _item : %2", (lbCurSel 1500), _item ]; }; ________________________________ and if i buy let's say another item witch would maybe be medkit then it will look like this:[["RPP_RepairKit","RepairKit",1]], [["RPP_Medkit","Medkit",1]] It shouldnt, i would hope it looks like...[["RPP_RepairKit","RepairKit",1], ["RPP_Medkit","Medkit",1]] Share this post Link to post Share on other sites
Naiss 28 Posted December 19, 2014 still getting the same error with the _item Share this post Link to post Share on other sites
Larrow 2823 Posted December 19, 2014 I expect you to still get the error but did anything get dumped to the clipboard or did it quit before it got the chance. If there is nothing on the clipboard change the coptToclipboard line to copyToClipboard format[ "Index : %1 , INV : %2", (lbCurSel 1500), RPP_Inventory ]; Share this post Link to post Share on other sites
Naiss 28 Posted December 19, 2014 this is what i got: Index : 1 , INV : [["RPP_RepairKit","RepairKit",1]] and this time no errors ---------- Post added at 16:58 ---------- Previous post was at 16:32 ---------- for someone reason first time the item get added into the inventory array it gives an error on that item when you try to drop it, bud on the second and on then it works just fine Share this post Link to post Share on other sites
Tajin 349 Posted December 19, 2014 (edited) Using the listbox index could provide very problematic depending on how your RPP_Inventory is handled. What if you drop the last of a certain item? This could leave your indexs out of sync with your RPP_Inventory array. Not if you refresh the listbox everytime. Anyway, I made some optimizations, changes, additions to the provided code. Maybe that helps or at least gives you some ideas. RPP_Inventory_Drop = { private ["_item","_have","_amount","_className"]; _i = lbCurSel 1500; if (_i < 0) exitWith { systemChat "Please Select an item to drop."; }; _item = RPP_Inventory select _i; _name = _item select 0; _have = _item select 2; _amount = round(parseNumber(ctrlText 1400)); if (_amount > _have) exitWith { systemChat "You can't drop more than you have."; }; _className = ""; { if ( (_x select 0) isEqualTo _name ) exitWith { _className = _x select 6; }; } count RPP_Items; if (_amount isEqualTo _have) then { 1500 lbDelete _i; RPP_Inventory deleteAt _i; } else { _item set [2, _have - _amount]; RPP_Inventory set [_i, _item]; }; _dropped = createVehicle [ _className, [ getPosATL player, 2, getDir player] call BIS_fnc_relPos, [], 0, "CAN_COLLIDE" ]; _dropped setVariable["amount",_amount,true]; }; RPP_Inventory_ItemAdd = { // [ itemClass, itemName, amount, ??shop?? ] RPP_Inventory pushBack [_this select 0,_this select 1,_this select 2]; }; RPP_buy = { private ["_shopname","_shop","_cfg","_class","_Price"]; _shopname = _this select 0; _shop = _shopname select (lbCurSel 1500); _cfg = _shop select 0; _class = _shop select 1; _Price = _shop select 2; [_cfg, _class, 1, _shop] call RPP_Inventory_ItemAdd; }; RPP_IntentoryLB_update { lbClear 1500; { lbAdd [1500, format ["%1",_x select 1]]; } foreach RPP_Inventory } I'd also suggest using more functions and being a bit more consistent with your parameter and variable names. That'll make it a bit easier to work with. I think part of the problem was how you added items to the inventory. You used: array = array + [[something]] instead of: array = array + [something] or better yet: array pushBack something Edited December 22, 2014 by Tajin Share this post Link to post Share on other sites
Larrow 2823 Posted December 19, 2014 (edited) Well thats not right, why is an array of one index adding to the listbox at index 1 rather than 0. Is there anything else your not showing in this thread that already manipulates the listbox items? If you want me to have a look at it zip it up and send it my way and ill have a look tomorrow for you. ____________________________ array = array + [[something]]There should be nothing wrong with that Tajin rp = []; rp = rp + [ [ 1, 2, 3 ] ]; rp = rp + [ [ 1, 2, 3 ] ]; //rp == [ [ 1, 2, 3 ], [ 1, 2, 3 ] ] array = array + [something]or better yet: array pushBack [something] The result of these two lines of code are not the same. Not if you refresh the listbox everytime. Of course that is what i was getting at but he does not show this happening Edited December 19, 2014 by Larrow Share this post Link to post Share on other sites
Naiss 28 Posted December 19, 2014 array = array + [something]; that wont work if i want to foreach in a list box because it needs to be a list for each item not the while array just 1 name from that array if you get what im trying to say and i think you got a new version of sqf or something because some of your commands that you are using is not giving me any color so if you got a link for a updated version of the sqf aswell :P ---------- Post added at 17:23 ---------- Previous post was at 17:15 ---------- the function you just showed me worked just fine the second time i added the item to RPP_Inventory but for some reason the first item just returns null and nill Share this post Link to post Share on other sites
Tajin 349 Posted December 22, 2014 "array = array + [something];" Bleh.... right, I just mixed something up there ^^. Anyway, you should still use pushBack instead. the function you just showed me worked just fine the second time i added the item to RPP_Inventory but for some reason the first item just returns null and nill That sounds like your "RPP_Inventory" variable is not properly initialized before your first call. Share this post Link to post Share on other sites