• 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!

HELP ME PLZ

reipor

Member
I want to make a system for buttons that when you press them you have 5 seconds until it returns to normal

GML:
//create event
timerpressed = false

//alarm0 event
timerpressed = false

//step event

if place_meeting (x,y,obj_player){
    timerpressed = true
     alarm[0] = 300;
}
if timerpressed = false{
    sprite_index = botao_unpressed_04
 
}

if timerpressed = true{
    sprite_index = botao_pressed_04
}
if you could help me, i am new and i am still learning
 
Try this.
GML:
//Mouse Pressed event
timer_pressed = true;                //This sets onyour flag
alarm[0] = room_speed*5;        //5 is the duration in seconds
sprite_index = botao_pressed_04;   //Reset your sprite



//Alarm 0 event
timer_pressed = false;               //This sets it off 5 seconds later
sprite_index = botao_unpressed_04;   //Reset your sprite
 

reipor

Member
Try this.
GML:
//Mouse Pressed event
timer_pressed = true;                //This sets onyour flag
alarm[0] = room_speed*5;        //5 is the duration in seconds
sprite_index = botao_pressed_04;   //Reset your sprite



//Alarm 0 event
timer_pressed = false;               //This sets it off 5 seconds later
sprite_index = botao_unpressed_04;   //Reset your sprite

Mouse Pressed event (???)

why mouse pressed event?
 
ok, communication breakdown here.
If you mean the human in front of the computer that clicks with his mouse cursor on a GUI button, then yes, use mouse_pressed or mouse_release event, not the step, and not place_meeting

If you mean like a player opening a chest like in Zelda then no, dont use mouse events
 

reipor

Member
ok, communication breakdown here.
If you mean the human in front of the computer that clicks with his mouse cursor on a GUI button, then yes, use mouse_pressed or mouse_release event, not the step, and not place_meeting

If you mean like a player opening a chest like in Zelda then no, dont use mouse events
i meant, when player touches the obj of button, the code starts
 
Then you'll somehow have to check if you'r collision didn't already happened, otherwise your alarm will be stuck at 300
GML:
if ((place_meeting (x,y,obj_player)) && (alarm[0] == -1)){
    timerpressed = true
     alarm[0] = 300;
}
Or simply use the collision event.
 
  • Like
Reactions: Tyg
Minor advice/nitpick:

In GML events are pre-defined things you create and then assign code in the object editor (creation, new step begins, alarms going off, ect)

Calling everything an event in your code comments makes your code slightly confusing to read at a glance

Edit: 💩💩💩💩, I'm moron. You were marking what event each block of code was in to use only one code box. Hold on and let me read this.

Edit 2: for what I think your attempting you need to have it set the timed flag when place_meeting (x, y, mouse.x, mouse.y) and then make sure it checks to see if the flag has already been set before setting it again. something like.

GML:
if place_meeting (x, y, mouse.x, mouse.y) and button_touched = false {

button_touched = true;
alarm[0] = 100; //change alarm time to desired
sprite_index = button_pressed_spr; //insert your sprite name here

}

Then of course your alarm sets the sprite back and sets button_touched to false so it can be activated again
 
Last edited:
Top