Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Having made the first game in Game Maker, Catch the Clown, I realised there was no way to win or lose.

Winning is easy enough, set a maximum score and a test that fires whenever a score increments, but losing has proved challenging. I had an idea; if the player attempts to click on the clown but misses he/she loses a life. I have tested every check, read the manual and looked through forums but I can't find a way to do this.

I also can't figure out where to put the event. I tried on the clown; tests like checking to if there would be a collision between where the click occurred and where the clown is... nothing works. I am at a complete loss so any help would be greatly appreciated.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This question concerns the order of events (when they are relatively called to one another). My answer takes advantage of the fact that mouse click events occur between Begin Step and End Step events. That means one solution would be the following:

  1. Have an obj_controller (bad name and design practice, but fairly commonly done with GM) that has a clicked variable and a hit variable.
  2. In obj_controller's Begin Step, set hit and clicked to false
  3. In obj_controller's Global Mouse Left Pressed event (this would indicate there has been a hit somewheres on screen, possibly a misfire, possibly not), set the clicked variable to true
  4. Have an object called obj_clown that is the target your user is trying to hit.
  5. In obj_clown's Left Pressed event, increment score, tell obj_controller that there has been a verified hit by setting obj_controller's hit variable to true (this can be done using the following GML:

    ///Tell the obj_controller a hit was made
    with(obj_controller) {
        hit = true;
    }
    

    ), and destroy itself (so the clown is gone).

  6. In obj_controller's End Step event, check if clicked is true and hit is false. This means there has been a click somewheres that isn't a clown (because the clown would've told it that the hit was good) and we can decrement a life

I hope that's not too confusing. I've slapped together a GM:S example for you to look at (it works! although it's kind of ugly and there's no sound or polish and losing all your lives or killing all the clowns doesn't mean anything)

share|improve this answer
    
Hi Jeff, thank you so much for this, exactly what I was looking for, works like a charm and revealed a whole extra level of thinking for me to boot! I'll admit I was a little confused but that was through lack of knowledge (around using variables in GM, I've only done this one tutorial) but a little digging cleared that right up. –  CLockeWork May 21 '13 at 18:41
    
If you are having any trouble understanding the GML I could try to look up the equivalent drag and drop. Not sure what you use, but I mostly use GML. I tried making most of this with D&D to be more accessible though –  Jeff May 21 '13 at 20:32
    
It was, thanks Jeff, just required me to increase my understanding a little. I had an idea about how to send the variable update with D&D this morning so I'll put that to the test tonight. The main issue with GML was just a lack of access to it... I'm assuming there's a way to do it all in code but the only way i could find to add your code snippet was by using the D&D code function, or is that all I need to do? Thanks again :) –  CLockeWork May 22 '13 at 8:39
    
@CLockeWork: To add GML, you have to go through D&D (either the Execute Code command or the Execute Script command) –  Jeff May 25 '13 at 13:41
    
I should have waited to go through the other tutorials before I asked that. Thanks Jeff, I've started doing all my work with code instead of D&D, it's much tidier. –  CLockeWork May 25 '13 at 15:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.