U
uni00
Guest
Hello. I created an inventory that contains up to 4 items, referring to the blog here. Pressing the Enter key on an item removes it from the field and puts it in your inventory. Now, let's assume that four items are filled. This script finds a place where you can put an item and returns true if you put one. Returns false if there is no place to enter. Until now, I started instance_destroy(); just by pressing the enter key, so the item disappeared regardless of whether it was stored. However, if you can pick up false and true in the script, the item will not disappear if you do not press the Enter key to enter. What should I do to pick up this judgment? I intend to invoke instance_destroy(); if true.
thanks!
thanks!
GML:
-o_player_create--
global.inv = ds_grid_create(4,2);
ds_grid_clear(global.inv,0);
GML:
--script--
/// @description Adds an item and a quantity into the inventory in a valid slot.
/// @function scr_gain_item(item_ID, amount);
/// @param item_ID
/// @param amount
var iid = argument0;
var amount = argument1;
var slot = 0; //A temporary variable to loop through the slots
var inventory_width = ds_grid_width(global.inv);
while (slot < inventory_width)
{
if (global.inv[# slot, 0] == iid || global.inv[# slot, 0] == item.none)
{
global.inv[# slot, 0] = iid;
global.inv[# slot, 1] += amount;
return true; //Did set the slot (return/exit)
}
slot ++;
}
return false; //Did not set slot
GML:
--item_collision(item and o_player)--
if(keyboard_check_pressed(vk_enter)){
instance_destroy();
}
GML:
-item_destroy_event-
scr_gain_item(item.draw_set,1);