just makin games
Member
FIRST OF ALL: THIS IS JUST A QUERY. I'm not asking for a programming fix or anything here. So if you're here to fix someones bug, this isn't the post for you.
I don't expect this to be taken as a programming error that needs to be fixed or anything, just a bit of a question.
I'm working on a zombie survival game, and I just implemented a system for picking things up and keeping them in an inventory.
First of all, I followed this from these tutorials (
) and noticed a bug. The amount the player is carrying of a certain item isn't actually showing up, its just staying as 1. if anyone has an answer to this, it would be helpful, but that's not the main focus of this.
I wanted to know how I would go about making the player able to select specific items and drop / use them. The inventory has a bunch of static images with a number beside them that corresponds to how much of that item you're carrying and that's pretty cool, but how would I make the player able to seek out specific items and use or drop them in any way?
heres the code I've used.
thanks guys
I don't expect this to be taken as a programming error that needs to be fixed or anything, just a bit of a question.
I'm working on a zombie survival game, and I just implemented a system for picking things up and keeping them in an inventory.
First of all, I followed this from these tutorials (
I wanted to know how I would go about making the player able to select specific items and drop / use them. The inventory has a bunch of static images with a number beside them that corresponds to how much of that item you're carrying and that's pretty cool, but how would I make the player able to seek out specific items and use or drop them in any way?
heres the code I've used.
shouldShowInventory = false
(global.inventory is set elsewhere, it is a ds_map, global.inventoryItems is set elsewhere, it is a ds_list.)
(global.inventory is set elsewhere, it is a ds_map, global.inventoryItems is set elsewhere, it is a ds_list.)
if shouldShowInventory {
draw_sprite(sinventory,0,0,0) //background UI sprite
var len = ds_list_size(global.inventoryItems);
for (var i = 0; i < len; i++) {
var key = ds_list_find_value(global.inventoryItems, i)
var value = ds_map_find_value(global.inventory, key)
var cam = camera_get_active()
var camX = camera_get_view_x(cam)
var camY = camera_get_view_y(cam)
var GRID = 32
draw_sprite_stretched(object_get_sprite(key), 0, camX + 32, (camY + i * GRID) + 64,48,48)
draw_text(camX + 32 + GRID * 2, camY + i * GRID + 64,": "+string(value))
show_debug_message("drew inventory")
}
}
draw_sprite(sinventory,0,0,0) //background UI sprite
var len = ds_list_size(global.inventoryItems);
for (var i = 0; i < len; i++) {
var key = ds_list_find_value(global.inventoryItems, i)
var value = ds_map_find_value(global.inventory, key)
var cam = camera_get_active()
var camX = camera_get_view_x(cam)
var camY = camera_get_view_y(cam)
var GRID = 32
draw_sprite_stretched(object_get_sprite(key), 0, camX + 32, (camY + i * GRID) + 64,48,48)
draw_text(camX + 32 + GRID * 2, camY + i * GRID + 64,": "+string(value))
show_debug_message("drew inventory")
}
}
thanks guys
GML:
//code in collision with pickup parent
var key_pickup = keyboard_check_pressed(ord("E"))
if key_pickup {
if other.object_index != noone {
var key = other.object_index;
var value = 1;
if ds_map_exists(global.inventory,key) {
value += ds_map_find_value(global.inventory,key);
}
else {
ds_map_add(global.inventory,key,value)
ds_list_add(global.inventoryItems,key)
}
instance_destroy(other)
}
}
Last edited: