W
Warmachine33
Guest
Ok so I'm trying to get it so when I pick up my items a notification will pop up. I can get it to pop up when I drop items but not when I pick them up. I get a error message like below. Appreciate any help and will post some more code below if you nee more info or code let me know.
Code:
FATAL ERROR in
action number 1
of Step Event0
for object obj_item:
Unable to find any instance for object index '9' name 'inventory'
at gml_Script_create_notification (line 7) - var _item_name = inventory.ds_items_info[# 0, _item_index];
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_create_notification (line 7)
called from - gml_Object_obj_item_Step_0 (line 57) - if instance_exists(create_notification(1, in)){;
Code:
///create_notification script
///description create_notification(number,item_index)
/// @arg number
/// @arg item_index
var _num = argument0;
var _item_index = argument1;
var _item_name = inventory.ds_items_info[# 0, _item_index];
if(!instance_exists(obj_notification)) {
instance_create_layer(0, 0, "Instances", obj_notification);
}
with (obj_notification) {
//create grid
if(!ds_exists(ds_notifications, ds_type_grid)) {
ds_notifications = ds_grid_create(2, 1);
var _notif_grid = ds_notifications;
_notif_grid[# 0, 0] = _num;
_notif_grid[# 1, 0] = _item_name;
}
//add to grid
else {
var _notif_grid =ds_notifications;
var _grid_height = ds_grid_height(_notif_grid);
var _found = false;
for (var _yy = 0; _yy < _grid_height; _yy++) {
if (_item_name == _notif_grid[# 1, _yy]) {
_notif_grid[# 0, _yy] += _num;
_found = true;
break;
}
}
if (!_found) {
ds_grid_resize(_notif_grid, 2, _grid_height + 1);
_notif_grid[# 0, _grid_height] = _num;
_notif_grid[# 1, _grid_height] = _item_name;
}
}
//reset the fade away
event_perform(ev_other, ev_user0);
}
Code:
///Obj_item step event
var picked_up = true;
if(drop_move){
x = lerp(x, goal_x, 0.1);
y = lerp(y,goal_y, 0.1);
if(abs(x- goal_x) < 1 and abs(y- goal_y) < 1) { drop_move = false; }
}
else {
if(!keyboard_check(ord ("O"))) exit;
var px = global.PlayerID.x;
var py = global.PlayerID.y;
var r = 32;
if(point_in_rectangle(px, py, x-r, y-r, x+r, y+r)){
//Are we on top of the player
r = 2;
if(! point_in_rectangle(px, py, x-r, y-r, x+r, y+r)){
//move towards the player for pickup
x = lerp (x, px, 0.1);
y = lerp(y, py,0.1);
}else { // pickup item
var in = item_num;
with(inventory){
var ds_inv = ds_inventory;
//check if item exists in inventory already
var yy = 0; repeat(inv_slots){
if(ds_inv[# 0, yy] == in){
ds_inv[# 1, yy] += 1;
picked_up = true;
break;
} else {
yy += 1;
}
}
//otherwise add item to an empty slot if there is one
if(!picked_up) {
yy = 0; repeat(inv_slots){
if(ds_inv[# 0, yy] == item.noone){
ds_inv[# 0, yy] = in;
ds_inv[# 1, yy] += 1;
picked_up = true;
break;
} else {
yy += 1;
}
}
}
}
//destroy Item if picked_up
if(picked_up){
create_notification(1, in);
instance_destroy();
show_debug_message("picked up an item.");
}
}
}
}