• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [SOLVED] Execution Error - Variable Index [0,1] out of range [1,1] - -1.backpack_slot(100006,1)

  • Thread starter Tran Thi Huyen Trang
  • Start date
T

Tran Thi Huyen Trang

Guest
Hello everyone! I'm having trouble with my achievement system that I can't seem to fix. I've tried a lot of different things but nothing seems to work. so I'm just going to show you my code and hopefully you can help. If your not sure what some of the code means, ask me and I will explain it :)

Error:
Code:
FATAL ERROR in
action number 1
of Draw Event
for object obj_inventory:

Push :: Execution Error - Variable Index [0,1] out of range [1,1] - -1.backpack_slot(100006,1)
 at ��t  F� ct_obj_inventory_DrawEvent_1 (line 74) -         if(backpack_slot[i] != noone)
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_obj_inventory_DrawEvent_1 (line 74)
Create:
Code:
///initialize inventory
slot_number = 20;
inventory_width =4;
///new
backpack_slot_number = 9;//6;
backpack_slot_width = 9;//1
backpack_slot_height = 1;
//----For-Loop emptying all slots----
for(var i = 0; i < slot_number; i++)
{
    slot[i] = noone;
    slot_n[i] = 0;
    weapon_slot = noone;
    shield_slot = noone;
    backpack_slot[i] = noone;
    backpack_slot_n[i] = 0;
}
mouse_slot = noone;
mouse_slot_n = 0;
x_off = 200;
backpack_slot = noone;
backpack_slot_n = 0;
Draw:
Code:
//----Drawing backpack slots----

//Checking backpack_slot_number and draw as many sprites as backpack_slot_number provides
for(i = 0; i < backpack_slot_number; i++)
{
    var xx = i mod backpack_slot_width;
    var yy = i div backpack_slot_width;
    
    
//Drawing backpack slots

draw_sprite(spr_backpack_slot, 0, 8 + xx * 32, 268 + yy * 32);

    
        if(backpack_slot[i] != noone)
        {
            //Drawing item and number etc.
            draw_sprite_ext(sprite[backpack_slot[i]], 0, 8 + xx * 32 + 16 + 3, 268 + yy * 32 + 16 + 2, 1, 1, 0, c_black, .4);    //Shadow
            draw_sprite(sprite[backpack_slot[i]], 0, 8 + xx * 32 + 16, 268 + yy * 32 + 16);    //Drawing the sprite of the item inside the slot
            draw_set_font(fnt_slot_number);
            draw_set_color(c_white);
           // if(stackable[backpack_slot[i]] = true)
           // {
             //   draw_text(4 + 8 + xx * 32, 2 + 268 + yy * 32, string(backpack_slot_n[i]));     //Drawing item amoount onto slot
           // }
            draw_set_font(-1);
            draw_set_color(-1);
        }
      
}


//----Drawing sprite on mouse after clicking----

//Check if not dragging a weapon or armor (items that cant stack)
if(mouse_slot != noone)
{
    draw_sprite_ext(sprite[mouse_slot], 0, mouse_x - x_off + 11, mouse_y - y_off + 10, 1, 1, 0, c_black, .4);   //Shadow
    draw_sprite(sprite[mouse_slot], 0, mouse_x - x_off + 8, mouse_y - y_off + 8);
    draw_set_font(fnt_slot_number);
        draw_set_color(c_white);
        //Check if dragging stackable item
       // if(stackable[mouse_slot] = true)
      //  {
            //If so -> draw item amount
        //    draw_text(mouse_x - 12 - x_off, mouse_y - 13 - y_off, string(mouse_slot_n));            //Drawing item amount onto item whilst dragging
       // }
        draw_set_font(fnt_hud);
        draw_text_colortags(mouse_x + 20 - x_off, mouse_y + 13 - y_off, string(item_name[mouse_slot]));        //Drawing item name at mouse pos whilst dragging
        
    //IF right-clicking show info
        if(mouse_check_button(mb_right))
        {
            show_info_box = true;
            
            //Drawing the actual info_box
            draw_text_colortags(mouse_x + 20 - x_off, mouse_y + 28 - y_off, string(info_text[mouse_slot]));
            
        }
        else
        {
            show_info_box = false;
        }     
        draw_set_font(-1);
        draw_set_color(-1);
}
Thanks for the help! :p
 

Simon Gust

Member
Make sure you don't accidentally delete your backpack after you create it.

In your create event you are creating your backpack_slots correctly,
the problem is that you delete again right after by writing
Code:
backpack_slot = noone;
backpack_slot_n = 0;
Those 2 lines should be before the for-loop that creates your backpack.
 
T

Tran Thi Huyen Trang

Guest
Make sure you don't accidentally delete your backpack after you create it.

In your create event you are creating your backpack_slots correctly,
the problem is that you delete again right after by writing
Code:
backpack_slot = noone;
backpack_slot_n = 0;
Those 2 lines should be before the for-loop that creates your backpack.
Thank you so much, it works.
 
Top