GML How to trigger alarm when mouse click the object?

Fizz

Member
im just trying to do what i think like making alarm first then use left pressed to trigger it but that cant, or i think this was some bug, cause i can run it but doesnt pop up the game display.

i try using

Create > alarm[0]=10;
room="theroom"
Left Pressed> if (alarm[0] <=10) {
room_goto(theroom);
}

Some help please...

#sorryforbadenglish
 

Fizz

Member
You're passing a string into room_goto its meant to be an index. Get rid of the quotation marks.
sorry, but even i do that it still not works, and actually i want to make some delay after click the object, after the delay time over it will go to the next room.
 

JackTurbo

Member
In that case you're using the alarm wrong. And I dont really get what your code is meant to be doing? why all the "greater than" checks?
Also I'm semi-sure that room is already a keyword by default so use a different variable name for that.


To acheive what your describing you'd want something that looks more like this:

Code:
//CREATE EVENT
destinationRoom = roomnamehere;


//STEP EVENT
if (mouse_check_button_pressed(mb_left)){
    alarm[0] = 10;
}


//ALARM [0] EVENT
room_goto(destinationRoom);
 

Fizz

Member
ah tysm that really work, and now i understand whats wrong, i think because i used left pressed event to do the trigger without an alarm event and some wrong arguments
:)
 

Fizz

Member
In that case you're using the alarm wrong. And I dont really get what your code is meant to be doing? why all the "greater than" checks?
Also I'm semi-sure that room is already a keyword by default so use a different variable name for that.


To acheive what your describing you'd want something that looks more like this:

Code:
//CREATE EVENT
destinationRoom = roomnamehere;


//STEP EVENT
if (mouse_check_button_pressed(mb_left)){
    alarm[0] = 10;
}


//ALARM [0] EVENT
room_goto(destinationRoom);
ah sorry, i just try this, but how to make the click only work for the object, i try it when i press anything on screen not the object, it do the same(go to next room)

#anotherhelp
 

JackTurbo

Member
Look at the code I posted, naturally that is the case because all I did was check if the mouse button was pressed or not.

If you want it to only work when you click on your object then you'd have to incorporate some for of collision check.
You can read up on collision checking in the manual here: https://docs.yoyogames.com/source/dadiospice/002_reference/movement and collisions/collisions/index.html

The function that you would probably want in this case would be position_meeting.

Code:
//STEP EVENT
if (mouse_check_button_pressed(mb_left) && position_meeting(mouse_x, mouse_y, id) == true ){
   alarm[0] = 10;
}
Here I have amended the original step event to check if the mouse is pressed and that the calling instance is located where the mouse cursor currently is. I've passed the calling instance's id to position_meeting rather than its object name so that it is only checking for this particular instance of the object.
 

Fizz

Member
Look at the code I posted, naturally that is the case because all I did was check if the mouse button was pressed or not.

If you want it to only work when you click on your object then you'd have to incorporate some for of collision check.
You can read up on collision checking in the manual here: https://docs.yoyogames.com/source/dadiospice/002_reference/movement and collisions/collisions/index.html

The function that you would probably want in this case would be position_meeting.

Code:
//STEP EVENT
if (mouse_check_button_pressed(mb_left) && position_meeting(mouse_x, mouse_y, id) == true ){
   alarm[0] = 10;
}
Here I have amended the original step event to check if the mouse is pressed and that the calling instance is located where the mouse cursor currently is. I've passed the calling instance's id to position_meeting rather than its object name so that it is only checking for this particular instance of the object.
thank you again, you saved my day, before i was using mouse_check_button(mouse_x, mouse_y, id) and i think that was wrong. ;)
 
Top