Issue with alarms

JessDog

Member
Hello!

I'm having an issue in GMS 2.3.1 where my alarm events are linked between objects. For instance if I set alarm [0] to do something in one object it will do it to the another seperate object with an alarm [0]. I believed alarms were unique to objects? Is this just a bug?

For the meantime I got around it by using an alarm number which isn't being used by another object. However this will not last as a solution šŸ˜…

Has anyone else encountered this?

Thanks!
 
all built-in alarms are per instance, they are not global in scope.
You have something else wrong going on somewhere.

if you do something like obj_enemy.alarm[0], it will trigger on all enemies, tho. You have to set in at the instance-level, if that applies to your case.
 

kburkhart84

Firehammer Games
if you do something like obj_enemy.alarm[0], it will trigger on all enemies, tho. You have to set in at the instance-level, if that applies to your case.
Actually, last I heard, dot syntax runs on just one of the instances(theoretically whichever is the first one in the list). You have to use with() to hit all the instances of an object.

@JessDog As they say, alarms are a per instance thing so should not be "linked" as you are saying. Show us the code where you set the alarm please.
 
Actually, last I heard, dot syntax runs on just one of the instances(theoretically whichever is the first one in the list). You have to use with() to hit all the instances of an object.
I might be wrong, but I'm pretty sure it's working. But yeah, doing
GML:
with (obj_enemy){
    //set alarm
}
is the safest bet to hit all instances...well, I don't know about "safer", but at least looking better and easier to read
 

kburkhart84

Firehammer Games
Assignments are an exception. Assigning to object.variable assigns to all instances of object, unless you're using HTML5.
I might be wrong, but I'm pretty sure it's working. But yeah, doing
GML:
with (obj_enemy){
    //set alarm
}
is the safest bet to hit all instances...well, I don't know about "safer", but at least looking better and easier to read

Indeed, this is accurate. I guess since it isn't something I would consider good practice its something I forgot it technically does in the specific case of assigning variables. I still don't recommend it like that but there it is.
 

JessDog

Member
You are right! :D I had a with () statement that was the cause of the problem! Thanks so much for the help!

I was trying to create a fading platform when the player stands on it.

GML:
if (object_index == oFallingPlatform){
    
    var FallingPlatform = id;

    with(oPlayer){
        
        //If the Platform is Not Falling
        
        if (!FallingPlatform.startFalling)
        {
            
            //If the player touches the platfrom from above
            if(place_meeting(x,y+1, FallingPlatform) && !place_meeting(x,y, FallingPlatform))
            {
                
                //Makes it start disappearing
                if FallingPlatform.image_alpha > 0 FallingPlatform.image_alpha -= 0.06;
                
                //When faded destroys platfrom then triggers alarm to respawn
                if (FallingPlatform.image_alpha < 0.1){
                    
                    alarm[0]= room_speed*0.6;
                    instance_deactivate_object(FallingPlatform);
                    
                }
                
            }
            
            
            
        }
        
    
        
        
}
 
Top