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

Melee Attack variable error

S

Squirtle Plays

Guest
when I attack this happens

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

local variable hitID(100004, -2147483648) not set before reading it.
at gml_Script_PlayerState_Attack_Stab (line 23) - if (ds_list_find_index(hitByAttack,hitID) == -1)
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_PlayerState_Attack_Stab (line 23)
called from - gml_Object_object0_Step_0 (line 66) - case PLAYERSTATE.ATTACK_STAB: PlayerState_Attack_Stab(); break;


heres my code
Code:
hspeed = 0;
vspeed = 0;

//Start of the attack
if (sprite_index != sprite6)
{
    sprite_index = sprite6;
    image_index = 0;
    ds_list_clear(hitByAttack);
    
}

//Use attack hitbox & check for hits
mask_index = sprite61;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x,y,object2,hitByAttackNow,false)
if (hits > 0)

for (var i = 0; i < hits; i++)
    
        //if this instance has not yet been hit by this attack
        var hitID = hitByAttackNow[| i];
        if (ds_list_find_index(hitByAttack,hitID) == -1)
        
        ds_list_add(hitByAttack,hitID);
        with (hitID)
            
            
        
    

ds_list_destroy(hitByAttackNow);
mask_index = sprite01;

if (Animation_End())
{
    sprite_index =     sprite01;
    state = PLAYERSTATE.FREE;
}
 
T

ThePropagation

Guest
comment out the line after var hitID = hitBy and see if anything changes.
 
T

ThePropagation

Guest
The problem is that the ds_list_find_index doesn't know what hitID is
 
S

Squirtle Plays

Guest
But why I declared the variable and I tried removing it same thing happened
 
You are creating a list called hitByAttackNow. That list is empty. You are then assigning hitID to a position on that list. But the list is empty, so hitID doesn't get assigned anything (perhaps it gets set to undefined, but I'd have to check to make sure). This sounds like the problem to me. What do you WANT hitByAttackNow to hold?
 
Your for() statement looks like it's missing opening and closing braces. {}

This means that the only line executed by the for() loop is the line immediately after it where hitID gets created.

If hits == 0, hitID doesn't get created BUT, because you haven't blocked out your code properly, the ds_list_find_index() function gets run, trys to access the non-created hitsID variable, causing the error.
 
You are creating a list called hitByAttackNow. That list is empty. You are then assigning hitID to a position on that list. But the list is empty, so hitID doesn't get assigned anything (perhaps it gets set to undefined, but I'd have to check to make sure). This sounds like the problem to me. What do you WANT hitByAttackNow to hold?
Just fyi, instance_place_list() takes an empty list as an argument, and it's returns value is the number of instances that are found at that point. He is then checking the return value (hits) to make sure it is greater than 0 before accessing the list, to ensure the list is not empty, so that part of the code looks ok to me.
 
Ah, as I skimmed it, I read it as instance_place, not instance_place_list, lel.

As a sidenote (as you pointed out, IndianaBones) there's a few places within the code that you're neglecting brackets beyond what the actual problem was. It might seem quicker to skip out on those brackets, but you will almost inevitably run into problems like this. It's better to simply bracket -everything- properly, so you can be sure that your code is running in the way that you actually intend, rather than relying on the compiler to interpret ambiguous code style into a workable format.
 
S

Squirtle Plays

Guest
the reason I got rid of the brackets was it was giving me an error message my bad
 
Top