just makin games
Member
Hi there
so i fixed my inventory system so that is now features usable items, and it works... sometimes.
I noticed the keys of objects is changing every now and then, which is making the items unusable. Of course, i don't want my items to be unusable.
the previous key of the first aid kit was 49, but now its 50. whyyyyyyyyy
heres my code:
this was solved, but i've started getting errors. The key in the draw gui event isn't able to draw the sprite because the key has changed. Heres the error im getting:
___________________________________________
############################################################################################
ERROR in
action number 1
of Draw Event
for object player:
object_get_sprite argument 1 incorrect type (string) expecting a Number (YYGI32)
at gml_Object_player_Draw_64 (line 46) - draw_sprite_stretched(object_get_sprite(key), 0, 0 + 32, (0 + i * GRID) + 64,48,48)
############################################################################################
gml_Object_player_Draw_64 (line 46)
thanks for helping people who answered before by the way!!
so i fixed my inventory system so that is now features usable items, and it works... sometimes.
I noticed the keys of objects is changing every now and then, which is making the items unusable. Of course, i don't want my items to be unusable.
the previous key of the first aid kit was 49, but now its 50. whyyyyyyyyy
heres my code:
GML:
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_list_add(global.inventoryItems,key)
}
ds_map_set(global.inventory,key,value);
instance_destroy(other)
}
}
GML:
function inventory_use_items(){
item = argument0
if item = 52 {
nutrition += 50
audio_play_sound(soeat,0,0)
audio_play_sound(souse,0,0)
}
if item = 73 {
water += 45
audio_play_sound(sodrink,0,0)
audio_play_sound(souse,0,0)
}
if item = 90 {
water += 30
audio_play_sound(sodrink,0,0)
audio_play_sound(souse,0,0)
}
if item = 146 {
water += 15
audio_play_sound(sodrink,0,0)
audio_play_sound(souse,0,0)
}
if item = 35 {
nutrition += 25
audio_play_sound(soeat,0,0)
audio_play_sound(souse,0,0)
}
if item = 84 {
nutrition += 10
audio_play_sound(soeat,0,0)
audio_play_sound(souse,0,0)
}
if item = 44 {
global.hp += 15
audio_play_sound(sopainkiller,0,0)
audio_play_sound(souse,0,0)
}
if item = 49 {
global.hp += 60
audio_play_sound(somedkit,0,0)
audio_play_sound(souse,0,0)
}
GML:
if shouldShowInventory {
draw_sprite(sinventory,0,0,0)
var len = ds_list_size(global.inventoryItems);
for (var i = 0; i < len; i++) {
draw_set_colour(c_white)
clickleft = mouse_check_button_pressed(mb_left);
clickright = mouse_check_button_pressed(mb_right);
var key = ds_list_find_value(global.inventoryItems, i)
var value = ds_map_find_value(global.inventory, key)
if value = undefined {
value = 0
}
xMouse = device_mouse_x_to_gui(0)
yMouse = device_mouse_y_to_gui(0)
mouseinbox = false
var GRID = 32
draw_sprite_stretched(object_get_sprite(key), 0, 0 + 32, (0 + i * GRID) + 64,48,48)
draw_text(0 + 32 + GRID * 2, 0 + i * GRID + 64,": "+string(value))
if point_in_rectangle(xMouse,yMouse,0,(0 + i * GRID) + 72,0*GRID+32,(0 + i * GRID) + 102) {
draw_set_colour(c_green)
fireav = false
mouseinbox = true
if clickleft = true and value > 0 {
inventory_use_items(key)
ds_map_set(global.inventory,key,value - 1)
show_debug_message("CLICKED. KEY IS: "+string(key))
}
}
draw_rectangle(0,(0 + i * GRID) + 72,0*GRID+32,(0 + i * GRID) + 102,true)
}
}
this was solved, but i've started getting errors. The key in the draw gui event isn't able to draw the sprite because the key has changed. Heres the error im getting:
___________________________________________
############################################################################################
ERROR in
action number 1
of Draw Event
for object player:
object_get_sprite argument 1 incorrect type (string) expecting a Number (YYGI32)
at gml_Object_player_Draw_64 (line 46) - draw_sprite_stretched(object_get_sprite(key), 0, 0 + 32, (0 + i * GRID) + 64,48,48)
############################################################################################
gml_Object_player_Draw_64 (line 46)
thanks for helping people who answered before by the way!!
Last edited: