• 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!

GameMaker Line -1 of step event in event handler?

H

HawkHero

Guest
Hi there, noob here.

I'm working on a school project (final fantasy styled game) and this error happens on irregular intervals:



___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object Player:

Unable to find any instance for object index '101117' name '<undefined>'
at gml_Object_Player_Step_0
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_Player_Step_0 (line -1)


I don't know what i'm missing (or what line -1 is). here's the code for step of player:

Code:
if(!inCombat and !gameIsPaused and !gamewin)
{
    if(keyboard_check(ord("Z"))) playerSpeed = 4;
    else playerSpeed = 2;
    if(keyboard_check(vk_up))
    {
        if(!place_meeting(x,y - playerSpeed - 1,Colision) and !place_meeting(x,y - playerSpeed - 1,ColisionRound))
        {
            image_speed = 1;
            image_xscale = 1;
            sprite_index = spr_WarriorU;
            y -= playerSpeed;
        }
    }
    if(keyboard_check(vk_down))
    {
        if(!place_meeting(x,y + playerSpeed + 1,Colision) and !place_meeting(x,y + playerSpeed + 1,ColisionRound))
        {
            image_speed = 1;
            image_xscale = 1;
            sprite_index = spr_WarriorD;
            y += playerSpeed;
        }
    }
    if(keyboard_check(vk_left))
    {
        if(!place_meeting(x - playerSpeed - 1,y,Colision) and !place_meeting(x - playerSpeed - 1,y,ColisionRound))
        {
            image_speed = 1;
            sprite_index = spr_WarriorS;
            image_xscale = -1;
            x -= playerSpeed;
        }
    }
    if(keyboard_check(vk_right))
    {
        if(!place_meeting(x + playerSpeed + 1,y,Colision) and !place_meeting(x + playerSpeed + 1,y,ColisionRound))
        {
            image_speed = 1;
            image_xscale = 1;
            sprite_index = spr_WarriorS;
            x += playerSpeed;
        }
    }
    if(!keyboard_check(vk_up) and !keyboard_check(vk_down) and !keyboard_check(vk_left) and !keyboard_check(vk_right))
    {
        image_speed = 0;
        image_index = 0;
    }
}
else
{
    if(mana < maxMana + increaseMana and !dead)
    {
        mana += increaseMana;
    }
    if(HP <= 0)
    {
        dead = true;
        mana = 0;
        sprite_index = spr_Tombstone;
        hasSelectedEnemy = false;
    }
    else if(attacking)
    {
        if(!hasSelectedEnemy)
        {
            hasSelectedEnemy = true;
            selectedEnemy = chosenEnemy;
        }
        sprite_index = spr_Warrior_Attack;
        if(round(image_index) == 7 and !animation)
        {
            instance_create_depth(selectedEnemy.x, selectedEnemy.y - 5,
                                -1006, specialSpriteRoy);
            audio_play_sound(sfx_SwordSwing, 100, false);
            animation = true;
            specialSpriteRoy.sprite_index = spr_Slice;
        }
    }
    else if(special1)
    {
        if(!hasSelectedEnemy)
        {
            hasSelectedEnemy = true;
            selectedEnemy = chosenEnemy;
        }
        sprite_index = spr_Warrior_Special1;
        if(round(image_index) == 7 and !animation)
        {
            instance_create_depth(x - 5, y - 25, depth + 1, specialSpriteRoy);
            audio_play_sound(sfx_Fire, 100, false);
            audio_play_sound(sfx_MagicHit, 100, false);
            animation = true;
            specialSpriteRoy.sprite_index = spr_FirePillar;
        }
    }
    else if(special2)
    {
        if(!hasSelectedEnemy)
        {
            hasSelectedEnemy = true;
            selectedEnemy = chosenEnemy;
        }
        sprite_index = spr_Warrior_Special2;
        if(round(image_index) == 7 and !animation)
        {
            instance_create_depth(selectedEnemy.x, selectedEnemy.y - 5, -1006, specialSpriteRoy);
            audio_play_sound(sfx_Fire, 100, false);
            audio_play_sound(sfx_SwordSwing, 100, false);
            animation = true;
            specialSpriteRoy.sprite_index = spr_FireSlash;
        }
    }
    else if(special3)
    {
        if(!hasSelectedEnemy)
        {
            hasSelectedEnemy = true;
            selectedEnemy = chosenEnemy;
        }
        sprite_index = spr_Warrior_Special3;
        if(round(image_index) == 4 and !animation)
        {
            audio_play_sound(sfx_Unsheath, 100, false);
            animation = true;
        }
        if(round(image_index) == 21 and animation)
        {
            instance_create_depth(selectedEnemy.x - 2, selectedEnemy.y, -1006, specialSpriteRoy);
            audio_play_sound(sfx_SwordSwing, 100, false);
            animation = false;
            specialSpriteRoy.sprite_index = spr_Slash;
            hit = 0;
            if(chance(crit))
            {
                hit = (damage + irandom(rand) - selectedEnemy.defense) * 4;
                if (hit < 0) hit = 0;
                selectedEnemy.HP = approach(selectedEnemy.HP, 0, hit);
                attackType = 3;
            }
            else if (chance(accuracy))
            {
                hit = (damage + irandom(rand) - selectedEnemy.defense) * 2;
                if (hit < 0) hit = 0;
                selectedEnemy.HP = approach(selectedEnemy.HP, 0, hit);
                attackType = 1;
            }
            else attackType = 0;
            damageShow(selectedEnemy.x, selectedEnemy.y, attackType, hit);
        }
        if(round(image_index) == 35 and !animation)
        {
            audio_play_sound(sfx_Unsheath, 100, false);
            animation = true;
        }
        if(round(image_index) == 42 and animation)
        {
            audio_play_sound(sfx_WindSlash, 100, false);
            animation = false;
        }
        if(round(image_index) == 65 and !animation)
        {
            audio_play_sound(sfx_Stomp, 100, false);
            animation = true;
        }
    }
    else if(defending) sprite_index = spr_Warrior_Block;
}
The error is triggered when attacking an enemy.
Sorry if i'm missing anything, I don't post here often. Any help would be appreciated.
 
Last edited by a moderator:
R

Reyes

Guest
I'm sorry, the error is in the variable "chosenEnemy" and the assignment of this variable is not in that line of code. Maybe you are at the end of the create event, you must show all your code.
 
H

HawkHero

Guest
I'm sorry, the error is in the variable "chosenEnemy" and the assignment of this variable is not in that line of code. Maybe you are at the end of the create event, you must show all your code.
You were right. I finally found the reason behind the error: when chosenEnemy pointed at a destroyed instance, the game would crash
 
Top