• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED DS_List Inventory Management Issue

dialgpalkia

Member
Hi all,

I am in the process of modifying the inventory system for my game into one where I can move and organise items in my inventory.
I have a global ds_list called invList which contains the item type, number of items and durability (if necessary) of each item which is tracked by a control variable called slotID (so the first item in the inventory is at slotID = 0 up to 27).

When I open my inventory I have buttons setup (objButton_Inv) that are a visual cue for what item is in that slot. The object is basically a parent that shows different things depending on the parameters I give it.

In my controller object I have the following:
GML:
    if(inventoryOpen){
//Inventory Buttons are drawn on the GUI
        var _mouseX = device_mouse_x_to_gui(0);
        var _mouseY = device_mouse_y_to_gui(0);
        if(mouse_check_button_pressed(mb_left)){
            var _oldButton = instance_place(_mouseX, _mouseY, objButton_Inv); //Get the button at the mouse position.
            var _oldSlot = _oldButton.slotID; //Track the slot number of the old item.
            var _oldItem = global.invList[| _oldSlot]; //Get the information about the item from the list.
        }
        if(mouse_check_button_released(mb_left)){
            var _newButton = instance_position(_mouseX, _mouseY, objButton_Inv); //Get the button I have moved to
            var _newSlot = _newButton.slotID; //Track the slot number of the new item.
            var _newItem = global.invList[| _newSlot]; //Get the information about the item from the list.
            var _temp = _oldItem; //Temp storage of old item.
            global.invList[| _newSlot] = _temp; //Switch the new to the old
            global.invList[| _oldSlot] = _newItem; //Switch the old to the new
        }
    }
But when I open the inventory and left click on any button I get this error:
Code:
Variable <unknown_object>.<unknown variable>(100026, -2147483648) not set before reading it.
at gml_Object_objController_Step_0 (line 52) -                      var _oldSlot = _oldButton.slotID;
Any idea what's going on? As far as I understand all variables are being defined right. I used instance_position for _oldButton initially but then tried instance_place. It doesn't seem to get past the definition of _oldButton though and I can't figure out why.
 
Last edited:

dialgpalkia

Member
I fixed the error by adding && instance_place(_mouseX, _mouseY, objButton_Inv) into the if statements. But the items don't switch when I release the lmb in the new slot position.
 

dialgpalkia

Member
Post closed - I figured it out! Turns out the button wasn't registering that my mouse was within it's bounds so I changed that and adapted the code and it works!
 
Top