1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GML How to trigger alarm when mouse click the object?

Discussion in 'Programming' started by Fizz, Mar 7, 2019.

  1. Fizz

    Fizz Member

    Joined:
    Mar 7, 2019
    Posts:
    11
    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
     
  2. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    824
    You're passing a string into room_goto its meant to be an index. Get rid of the quotation marks.
     
  3. Fizz

    Fizz Member

    Joined:
    Mar 7, 2019
    Posts:
    11
    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.
     
  4. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    824
    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 likes this.
  5. Fizz

    Fizz Member

    Joined:
    Mar 7, 2019
    Posts:
    11
    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
    :)
     
  6. Fizz

    Fizz Member

    Joined:
    Mar 7, 2019
    Posts:
    11
    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
     
  7. JackTurbo

    JackTurbo Member

    Joined:
    Oct 19, 2016
    Posts:
    824
    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 likes this.
  8. Fizz

    Fizz Member

    Joined:
    Mar 7, 2019
    Posts:
    11
    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. ;)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice