Vladimir_spb
Member
I'm making quick inventory slots and don't understand how I can remove an item. I am using a script, but I do not understand what to write in arg [slot]. Help me please.
oPlayer step:
scrItemRemove
GML:
global.inv_toolbar = ds_map_create();
selected_slot = noone;
step:
var _key = string_digits(keyboard_lastchar);
if(_key != "") {
var _slot_index = (real(_key) + 9) mod 10;
selected_slot = slots[_slot_index];
keyboard_lastchar = "";
}
GML:
var _key = obj_inv_panel_toolbar.selected_slot.key;
if(_key == "food_apple") && keyboard_check_pressed(vk_space)
global.playerHP +=1;
//removes from the inventory
scrItemRemove(global.inv_toolbar, "food_apple", 1, ????? ); // what to write here???
GML:
///@func scrItemRemove(inv, key, amount, [slot])
///@desc removes an item from the inventory in general, or from a specific slot
///@arg {number} inv - inventory
///@arg {string} key - the key of the item to remove (ignored if removing from a specific slot)
///@arg {number} amount - number of items to remove. -1 removes all the items.
///@arg {number} [slot] - (optional) the slot index where the items are removed from
///@return {number} the amount of items actually removed (same as amount, given enough items)
function scrItemRemove() {
var _inv = argument[0];
var _slot = argument_count > 3 ? argument[3] : -1;
var _inv_items = _inv[? "items"];
//check if slot specified, and fetch key and amount
var _key, _amount;
if(_slot >= 0) {
_key = _inv_items[# EX_COLS.key, _slot];
_amount = argument[2] < 0 ? _inv_items[# EX_COLS.amount, _slot] : argument[2];
}
else {
_key = argument[1];
_amount = argument[2] < 0 ? scr_inv_count(_inv, _key) : argument[2];
}
//remove items
var _count = _scr_fn_item_remove(_inv, _key, _amount, _slot);
//fire notification
scr_ev_notify(_inv, EX_EVENTS.inv_updated);
//return items count
return _count;
}