Legacy GM [Solved]Need help with inventory system

G

Gustavo Miler

Guest
Hi, i'm new to programming and still learning, i want to make a inventory system that have visible slots at top and when i press Tab key it will show more slots, as a chest, for example. It's most based on Magicite and Roguelands system, for reference, i got to make it apear, but not disapear, it's an object called slot that replies himself in the room until it have enough i want, the problem is that i don't know how to destroy them, i've created a ds_grid with the information in a controller object so there's no problem by destroying them.
i made the inventory system entirely based on this https://forum.yoyogames.com/index.php?threads/flexible-inventory-system.34884/

It's basically a copy, could you guys help me?

the code at the controller object step event is like this:
Code:
var slot = 0;

if keyboard_check_pressed(vk_tab){
    if inventory_open = false{
    while (slot < 5)
     {
     inst1 = instance_create(x+8+(40*slot), y+50, oSlot);
     inst1.var_slot = slot;
     slot ++;
     }
     inventory_open = true;
     }
else{
    inventory_open = false;
    with inst1{
        instance_destroy();
    }
    }
    }
It only destroy the last slot object.
Thanks in advance.
 

brupibo

Member
You need one variable for each instance, here you have only one instance in the variable inst1. A quick fix for this code could be:

Code:
while (slot < 5) {
    inst[slot] = instance_create(x+8+(40*slot), y+50, oSlot);
    inst[slot].var_slot = slot;
    slot++;
}
Using inst[ ] you create an array with multiple instances (that you will need to access to delete)

To destroy all of them use the same method:

Code:
while (slot < 5) {
    with inst[slot] {
        instance_destroy;
    }
    slot++;
}

Read the manual about arrays to understand it better.
 
G

Gustavo Miler

Guest
Thank you! I'll be trying it right now, i tought about getting every item an id but couldn't tell in words, you helped me find a way! Later i'm gonna post the result.
 
G

Gustavo Miler

Guest
You need one variable for each instance, here you have only one instance in the variable inst1. A quick fix for this code could be:

Code:
while (slot < 5) {
    inst[slot] = instance_create(x+8+(40*slot), y+50, oSlot);
    inst[slot].var_slot = slot;
    slot++;
}
Using inst[ ] you create an array with multiple instances (that you will need to access to delete)

To destroy all of them use the same method:

Code:
while (slot < 5) {
    with inst[slot] {
        instance_destroy;
    }
    slot++;
}

Read the manual about arrays to understand it better.
Well, it worked! first when i tried the items duplicated between the main slots and the inventory slots, so i noticed their var_slot values were the same, i changed the
Code:
while (slot < 5) {
    inst[slot] = instance_create(x+8+(40*slot), y+50, oSlot);
    inst[slot].var_slot = slot;
    slot++;
}
into
Code:
while (slot < 5) {
    inst[slot] = instance_create(x+8+(40*slot), y+50, oSlot);
    inst[slot].var_slot = slot + 5;
    slot++;
}
Thank you brupibo, i'm really glad!
 
Top