GML Loops

Discussion in 'Programming' started by Joe Banko, Sep 10, 2019.

  1. Joe Banko

    Joe Banko Member

    Joined:
    Jun 21, 2019
    Posts:
    24
    Hopefully I can explain these questions so please bear with me.
    In theory;
    I have GMS2 setup for 60 game frames a second.
    Inside of a script I have a loop that needs to execute 30 times.
    Will the loop need 30 game frames to execute or will the loop run at machine speed inside of a single game frame?
    What happens if a loop runs longer than a game frame, will the loop execution be pushed to the next game frame or will it terminate before the loop conditions are met?

    All of this may be arbitrary with the speed of today's machines but there are exceptions. I DJ on the side and at one time was a pretty fair concert lighting designer. I found a package framework that really worked well with OSC and MIDI. The caveat was that any sort of loop had to be structured to run based on the application framework ~.27milliseconds. This produced some interesting coding caveats.
    Again this question may be totally out of concept for GMS2 but as I am now in a mode of optimizing my objects to run with as little delay as possible I am curious that I may run into any issues.

    Thanks in advance for any advice, comments!!

    joeb
     
  2. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,455
    Loops like for and while always run at the maximum speed that the CPU can afford, without room for the step cycle to act. I even have an article telling rookies to stop believing that one iteration of a loop equals one frame.

    If you want to repeat over time, you must use Step events, Alarms, Timelines or anything that isn't I/O blocking. Loops like for and while are always I/O blocking until they finish. Here's an example for repeating something 30 times with a pause of 0.5 seconds between each repeat:

    Create:
    Code:
    alarm[0] = 0.5*room_speed;
    Alarm 0:
    Code:
    /* Do something */
    alarm[0] = 0.5*room_speed;
     
  3. Joe Banko

    Joe Banko Member

    Joined:
    Jun 21, 2019
    Posts:
    24
    Thanks for the clarification! Just wanted to make sure that I wasn't going to run into Lemur issues (OSC/MIDI framework) I was using. I'm headed for the article.
    Thanks again!

    joeb
     
  4. Joe Banko

    Joe Banko Member

    Joined:
    Jun 21, 2019
    Posts:
    24
    Read thru the Loop Structures and the Flag Restrictions. Are these "stickies"? If not they should be. I am just entering my 3rd month of GMS2 coding and these concepts are important, IMNSHO.

    best,
    joeb
     
    Binsk likes this.

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