Time!

Happy New Year, and Happy Birthday, Eric!

Today I worked through Level 05 of the GPC. Level 03 introduced the irandom_range function, and provided a few examples of how I could throttle when actions occured – remember that in GML, action happens according to game speed (30 by default, or 30 steps/second).

This time, instead of leaving something up to random chance in hopes that it falls on the correct number or number range, we learned how to guarantee that the action occurred at a specified interval. This happened one of two ways:

  1. Using a counter – declare an instance variable in the create event for an object and set a value:
    //"counter" is the name of the variable, 
    //you could call it anything you wanted...
    //we set it to 0 so that it could count up 
    //in the STEP EVENT later
    
     counter=0

    Then create a step event (an event that cycles x# of iterations, 1 for every point you’ve set the game speed to):

    //add + 1 to the counter every time the step runs, 
    // 30 times per second by default
    
    counter=counter+1
    
    //when the counter reaches 150, or 5 seconds, 
    //do something
    
    if counter >=150 {
    ...code whatever you want to happen here...
     }

     

  2. Using Alarms – a built-in counter you can use. Each object can have up to 12 different alarms in it. They work like this:From another event’s code, enter:
    //where 0 is the alarm # (0-11) and 90 is the 
    //# of steps to wait (3 seconds)
    
     alarm[0]=90

    When the alarm #0 goes off, you can execute a piece of code by adding an Alarm Event for that specific alarm #:

    //e.g. create an explosion in a random location 
    //on the screen
    
     effect_create_above (ef_explosion,irandom_range (100,600),irandom_range (100,600),0,c_orange)
    
    //makes the alarm reset to 3 seconds
    // comment out of if you want it to
    //only happen once.
    
    alarm[0]=90

###

Level 05, Lesson 3: Getting Out of Sync

I’d like to preface this by acknowledging two points:

a. It’s FREE…I didn’t have to pay for ANY of this, yet all of it represents his own time, effort and money (i.e. hosting fees for his website, cost of recording equipment and software and so on).

b. John Janetka is teacher first and foremost – the GPC website, his YouTube channel and all the content therein are done in his spare time, and shared with me, you and everyone else who’s interested because he can and wants to, and with a ‘best-effort’ LoS.

Up to this point, I’d worked out that I needed to go to the website first, read the lesson, watch the video(s), then go back to the website to complete the challenges.

This pattern held true until you get to Level 05, Lesson 03.  The first thing he asks you to do in Part A is to read the notes on “L05-03-Reading01.pdf”. There isn’t a link to it on the website, or anywhere!

Then he asks you to watch the video 05-03-A to review said notes, but again, there is no such video on his YouTube channel!

Further down, he asks you to go through the questions in L05-03-ConceptQuestions01.pdf, which, like the notes, aren’t linked on the page or anywhere else…

So where are they? Well, after doing some digging, I found the word document versions buried in the Lv05 resource folder that was  included in the zip file from his resources page (the link labeled “Course Resources For All Levels”).

While I could have sworn that he’d touched on &&, || and != somewhere in one of his previous videos, they aren’t covered in any of the Level 05 videos up GPC-05-03-X1Preview. Not that it matters much as the lesson notes do a pretty good job explaining what they each do and when to use them.

By and large, the questions did a good job of reinforcing the lesson up to Part C, where the answers didn’t really follow the format he specified in his instructions…

SPOILER ALERT: Part C Questions and Answers

The question is phrased as follows:

Condition Is it ‘always true’ or ‘always false’?
if x>20 || x < 10
if points<20 || points>10
if life>=100 && life>50
if life>=100 && life<=0
if (points>10) && (points<20)

My answers were:

Condition Is it ‘always true’ or ‘always false’?
if x>20 || x < 10  Neither
if points<20 || points>10  Always True
if life>=100 && life>50 Neither
if life>=100 && life<=0  Always False
if (points>10) && (points<20)  Neither

His answers were:

Condition Is it ‘always true’ or ‘always false’ ?
if x>20 || x < 10 not always true
if points<20 || points>10 always true since one of the conditions must be true
if life>=100 && life>50 not always true  (ex. life is 25)
if life>=100 && life<=0 not always true  (ex. life is 50)
if (points>10) && (points<20) not always true

“Not always true” implies that it is sometimes false, when if fact, in some cases (e.g. if life>=100 && life<=0) it is ALWAYS False.

To check my answers, I wrote a test program which used the i_random_range function to generate a number every step between 0 and 200 (all of the examples above fall in that range).  From there, I ran each condition separately and had it display the result (true, false or both) each cycle, proving them correct.

I’ve provided it here, feel free to use it if you’d like.

…and yes, I probably spent waaaay more time on this than I reasonably should have, but it’s all good practice, right?

 

Later still in the same lesson, he tosses in some functions not previously covered (e.g. room_exists, room_goto_next etc.). I hope these will be covered in more depth later as this was the first time we’d played around with a project that had more than one screen.

Welp, on to the rest of the lesson! Stay tuned for more…

 

Image Credit: Don’t Hug Me, I’m Scared 2

Published by

Yousef

IT Manager by trade, game developer by heart.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.