• 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!

ds_grid inventory check for item (crafting)

M

MeanLikeCharlieSheen

Guest
Okay so my inventory system is based off of friendlycosmonauts farming rpg series - long story short i've been trying to get a little crafting system going were when i press the craft campfire button it checks inventory for enough wood then removes the wood and drops a forge item on the ground- been playing around with it for a few days managed to get it working in a few different ways just not as intended. with the code provided below i am only able to craft the campfire if woodenlogs was the last slot i was touching as (ss_item) = selected slot

So how would i go about looping through the inventory and finding the right slot





GML:
        var inv_grid = ds_inventory;
        var ss_item = inv_grid[# 0, selected_slot];

//Crafting Test
if(mouse_check_button_pressed(mb_left)){
    if(craft1 = true){ //Toggled true by pressing the craft button
        if(ss_item = item.woodenlogs){
            if (inv_grid[# 1, selected_slot] >= 5){
                inv_grid[# 1, selected_slot] -= 5;
                craft1 = false;
        
                //item crafted to drop
                var inst = instance_create_layer(obj_player.x,obj_player.y, "Instances", obj_item);
                with (inst){
                    item_num = item.campfire;
                    x_frame = item_num mod (spr_width/cell_size);
                    y_frame = item_num div (spr_width/cell_size);
                    }
            }
        show_debug_message("crafted a campfire");
        }
    }
}

<3 Sheen
 
You likely want ds_grid_value_x and/or ds_grid_value_y. Check them in the documentation.
They will return the x/y position of a particular value in the grid. So you can find the matching item in the grid and use the index to perform your checks and to remove the items from the inventory.
 
I can help, used same tutorial, you arent setting to none if 0 and do you update ss_item?
Would love to cooperate, since Im working on game too, im fresh :D

had similar problem, but could use only first item :DDD

and use if, otherwise you will be spammed with out of bound grid
if (selectedSlot >= 0) var ssItem = invGrid[# selectedSlot, ItemStats.ID];

And add text in corner that shows you selected slot, might be messed up,try to get as much info displayed as possible

While working on it, now it barely resembles code I borrowed, had debug bar with all the variables drawn from that code :D saved a lot of headbanging, cause weird things were going on

And no, debug function wasnt easier, seeing stuff IRT was better
 
Last edited:
M

MeanLikeCharlieSheen

Guest
GML:
        if (inv_grid[# 1, selected_slot] == 0){
            inv_grid[# 0, selected_slot] = item.none;
        }
@Paulenaz690 hahaha
I have this bit but it was under the bit i posted -- sorry for late reply still playing around with it, had a play around with the functions cloaked mentioned but havn't figured out how to work with those yet,

Drawing text to the screen showing more debug information now - will keep tinkering around

Thank-you for taking the time to help <3
 
Top