• 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 create event running multiple times

R

remmert

Guest
hey,
I have noticed that in one of my object the data is constantly being reset after some bug testing(very long and painful) and even re-writing my whole code again, I found out that the create event is run multiple times. I have no idea how this can be. I tested the other objects in my game and here it does not happen. Are there any setting or functions that can make this happen?

this is my create event code:
Code:
//alarm[0] is ussed for attack delay

//-----zombie variables
hp = 100
moveSpeed = 5 + random(2)
dmg =  20


//------movement variables
myPath = path_add()
followObject = 0
shooterId = noone //stores the id of the human that shot him(first one)


//------squad variables
leader = false // keeps track if he is a leader or not
//creatorId = instance_nearest(x,y,obj_human_dead).killerId    //id zombie that killed the human and created this zombie
leaderId = 999    //Id of his leader
show_debug_message("run setup")

leaderZone = 400 // the zone in which followers will attack humans
maxDisLeader = 1000 // farthest he will go away from leader


//state mashiene
enum zombieStates {
    idle,        //
    hunting,    //hunts a human
    shot,        //chases the shooter
    called
}
//--checks if the player is calling the zombies
if(instance_exists(obj_player)){
    if (obj_player.calling){ // if player is calling  set state to called
        currentState = zombieStates.called
    }else{
        currentState = zombieStates.hunting
    }
}else{currentState = zombieStates.hunting}
thank in advance for you guys help.
Remmert
 

NightFrost

Member
Besides event_perform I can't think of anything that could re-run a create event (never used that myself). You could do show_debug_message(id) in the create and check the log for duplicate values to make sure the event really is running again.

(Side note, you don't need to declare the enum again in every create, doing it just once at game start is enough as enums are automatically global.)
 
R

remmert

Guest
Besides event_perform I can't think of anything that could re-run a create event (never used that myself). You could do show_debug_message(id) in the create and check the log for duplicate values to make sure the event really is running again.
this is what I have done and that is what showed me that indeed the event is running almost every few seconds, what is very weird
 
R

remmert

Guest
ok this is really weird but when I change this code
Code:
mp_potential_step_object(followObject.x, followObject.y, moveSpeed, obj_wall)
to this

Code:
if(distance_to_object(leaderId) > 20){
                mp_potential_step_object(followObject.x, followObject.y, moveSpeed, obj_wall)    //move toward follow object
            }
I noticed that the zombies are only going through the create event again if they are close to the player. What I think happened is that mp_potential_step_object function is overflowing and making the instance reset.
 
Top