Android Why are my alarms not working properly on mobile devices but works properly on my computer?

D

datg232

Guest
Hi I have multiple alarms inside an object and they call the next alarm based on conditionals, these alarms shows different enemies during the game. these alarms works properly on my laptop but on android devices sometimes the game shows enemies before time and other crazy things. In fact, every time that I play the game on mobile I got a different behavior. First I used 60 fps and I tried with 30 fps. I used the clean button before every run button. Do yo know how to solve this?

Code:
/// @desc 6 ufo
if(obj_game.destroyed_ships >= 4)
{
    obj_game.destroyed_ships = 0;
    var xx_ufo = sprite_get_width(spr_ufo);
    var yy_ufo = 0;
    repeat(3)
    {
        instance_create_layer(xx_ufo, yy_ufo, "Instances", obj_ufo);
        xx_ufo += sprite_get_width(spr_ufo);
    }
 
    yy_ufo += sprite_get_height(spr_ufo);
    var xx_ufo = sprite_get_width(spr_ufo);
 
    repeat(3)
    {
        instance_create_layer(xx_ufo, yy_ufo, "Instances", obj_ufo);
        xx_ufo += sprite_get_width(spr_ufo);
    }
    if (alarm[2] <= 0) {
        alarm[2] = room_speed;
    }
}
else
{
    if (alarm[1] <= 0) {
        alarm[1] = room_speed;
    }
}
 
Last edited by a moderator:

Nocturne

Friendly Tyrant
Forum Staff
Admin
First thing to change is the <= 0... this should be

GML:
if alarm[2] < 0
Alarms run on 0 and end on -1, so you need to check it's less than 0 to be sure that it has already run.
 

chamaeleon

Member
I'm not keen on the idea of inspecting the value of the alarm counters myself. Either I do not use an alarm for some specific timing operation but keep track of it myself using my own variables, checking conditions as required, or, if the alarm event in itself is not sufficient, I make some state change (change a boolean, modify a counter, whatever..) and look at the values of those instead. I treat the alarm functionality a black box that I only know to set, reset, and rely on running its event code when the time is up.
 

Yal

šŸ§ *penguin noises*
GMC Elder
In the past, Alarms wouldn't even update unless their code had events, so if you don't have something in there... that could also lead to weird behavior.
 

Amon

Member
In the past, Alarms wouldn't even update unless their code had events, so if you don't have something in there... that could also lead to weird behavior.
Yep, I noticed that also. I just add a simple comment in its event then it behaves itself.
 
D

datg232

Guest
First thing to change is the <= 0... this should be

GML:
if alarm[2] < 0
Alarms run on 0 and end on -1, so you need to check it's less than 0 to be sure that it has already run.
Thanks now my code looks like this in every conditional but my game is not working properly
/// @desc ??
// 60 steps
if (alarm[0] < 0) {
alarm[0] = room_speed * 5;
}
 
D

datg232

Guest
I'm not keen on the idea of inspecting the value of the alarm counters myself. Either I do not use an alarm for some specific timing operation but keep track of it myself using my own variables, checking conditions as required, or, if the alarm event in itself is not sufficient, I make some state change (change a boolean, modify a counter, whatever..) and look at the values of those instead. I treat the alarm functionality a black box that I only know to set, reset, and rely on running its event code when the time is up.
Well I thought that something like this was going to work, I mean this code is very simple, the first alarm starts after the drag event.alarm structure.PNG
 
D

datg232

Guest
In the past, Alarms wouldn't even update unless their code had events, so if you don't have something in there... that could also lead to weird behavior.
In fact, I have multiple events on this objects and multiple alarms, just with the create event this should work right? because is not working. I updated my GameMaker version with the project I think that maybe I need to create my project again because this game have many bugs on android version, I dont now why the behavior is different from pc version.
 

Attachments

Nocturne

Friendly Tyrant
Forum Staff
Admin
At this point, I'd export the project as a YYZ and then file a bug report with YYG and include a link to the file. Alarms should work the same on all platforms and if it's not then something is up...
 
D

datg232

Guest
At this point, I'd export the project as a YYZ and then file a bug report with YYG and include a link to the file. Alarms should work the same on all platforms and if it's not then something is up...
Thanks, but I decided to change alarm code to step code and now is working.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Thanks, but I decided to change alarm code to step code and now is working.
That's great for you, but doesn't help any other user that may come across the issue and not know how to deal with it. Filing a bug report helps everyone and also makes the product better, so please consider doing it.
 

TheouAegis

Member
Put in a show_message(room_speed) somewhere (not a Create Event) and run the project on Android... It should not show a 0 or negative number.
 
Top