By hovering the mouse in the option the event fires continuously

Asked

Viewed 34 times

-2

Basically, I was making a menu for my game, it’s simple, only two options so far ("Start", "Leave"). So far so good, I went to program it. When I went to test and passed the mouse over the option, it played non-stop, and only stopped when I took the option.

var isDespertar = false;

if isDespertar == true and place_meeting(x,y,obj_btn_start) {
    audio_play_sound(snd_change_option,1,0);
    show_debug_message("executou");
    var isDespertar = false;
} else {
    var isDespertar = true;
    show_debug_message("false")
    //audio_stop_sound(snd_change_option);
}

In the same obj_mira, there is a step, which contains:

if place_meeting(x,y,obj_btn_start){
    obj_borda_start.visible = false;
    obj_borda_leave.visible = true;
    
    alarm_set(0,1);
} else if place_meeting(x,y,obj_btn_leave){
    obj_borda_leave.visible = false;
    obj_borda_start.visible = true;
} else {
    obj_borda_leave.visible = false;
    obj_borda_start.visible = false;
}

The first code is an alarm, the place_meeting, if true, will run the alarm.

He’s in the obj_mira (objective). The most frustrating thing is that I know why it’s happening, but I don’t know how to solve it. If you could help me, I would be most grateful!

Just to make it "easier" to understand how it works: Let’s say we have a cube, it’s got a "yellow" value, right. Let’s create a condition, which executes if "cube is purple" (which it is not, right?), but if it is not (Else), the cube will become purple, so the idea was that the variable would turn purple, and the code would start to be read as if the cube were purple, that is, it would touch the sound, but then, at the end of the code, it would become green, preventing it from playing all the time the sound (that was the idea), but, well... It’s not working :/... I’ve asked for help on a Discord, but it came to nothing.

  • I don’t understand how your code works, if you don’t explain the details, for example what it contains in obj_btn_start ... I recommend that you create a minimal and VERY SIMPLE example that we can easily copy and run to understand where you failed

  • My mistake, sorry. There’s nothing in obj_btn_start, only obj_mira. What’s in obj_mira is a step, which contains (not only that, of course, but that’s basically what triggers the alarm. I will put the step code in the post. E, finally there is an alarm event, What is in the code is an alarm (0).

1 answer

0

Oops! I had an idea, which basically was to put in a create the variable, which would receive "true" value, then in the step...:

if place_meeting(x,y,obj_btn_start) and global.ativardesativar == true {
    show_debug_message("ola");
    global.ativardesativar = false;
} else if !place_meeting(x,y,obj_btn_start) and global.ativardesativar == false {
    show_debug_message("tchau");
    global.ativardesativar = true;
}   

If you like, I would like to ask for suggestions on how to improve it.

Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.