Alarms inside functions

feamagno

Member
Is there any way to set an alarm from inside a function? I want to put some random delay to create an instance from inside a script function, but I couldn't figure out how to.
 

chamaeleon

Member
If you call a plain function (not a struct function) from an instance Step or Create event (for example) and your function sets alarm 0 to some value, that alarm should be set. Might want to post complete code for your attempt.
 

feamagno

Member
If you call a plain function (not a struct function) from an instance Step or Create event (for example) and your function sets alarm 0 to some value, that alarm should be set. Might want to post complete code for your attempt.
Its a "Script Function"
GML:
function blood(dmg,spd,objhiting,objhited)
{
    rd = irandom_range(dmg,dmg*2)
    repeat(rd)
    {
        //where alarm should go lol
        with(instance_create_layer(objhited.x,objhited.y,"Instances_projectile",obj_blood))
        {
            speed = spd/3
            direction = point_direction(objhiting.x,objhiting.y,objhited.x,objhited.y)
            direction += irandom_range(-40,40)
        }
    }
}
 
Last edited:

chamaeleon

Member
Suspiciously lacking from your function code is a line that sets the alarm. Do you wish the alarm to be set on the instance that runs the function, or on the instances created in the with() statement? If the instance calling the function, doesn't make sense to do it in the loop, but rather before or after it. For created instances, set it inside the with() statement code block (since that code runs in the context of the newly created instance).
 
If you want a delay before obj_blood is created, you'll have to have this code:
Code:
with(instance_create_layer(objhited.x,objhited.y,"Instances_projectile",obj_blood))
        {
            speed = spd/3
            direction = point_direction(objhiting.x,objhiting.y,objhited.x,objhited.y)
            direction += irandom_range(-40,40)
        }
Inside of the alarm in the calling instance, and then simply set that alarm in the function. I think you're trying to do the old thing where people think "Ah, if there's some sort of loop here, it'll create a delay", when that's not how loops work.
 

feamagno

Member
If you want a delay before obj_blood is created, you'll have to have this code:
Code:
with(instance_create_layer(objhited.x,objhited.y,"Instances_projectile",obj_blood))
        {
            speed = spd/3
            direction = point_direction(objhiting.x,objhiting.y,objhited.x,objhited.y)
            direction += irandom_range(-40,40)
        }
Inside of the alarm in the calling instance, and then simply set that alarm in the function. I think you're trying to do the old thing where people think "Ah, if there's some sort of loop here, it'll create a delay", when that's not how loops work.
Ty for the tips!
Thanks @RefresherTowel, I completely misunderstood the question at hand.
Ty u too!
 
Top