Processing, Timers and GS

fmakawafmakawa Member Posts: 565

Hi folks, so I've found myself having to use timers a lot lately and I'm baffled so I've been trying to understand a few things. I'm aware that GS is NOT completely sequential and it processes things as bottom-up within scenes and top-bottom within actors. But within these parameter I have a few questions: How long does GS take to process each bit of instructions or run loops or search tables? Does it continue running additional code in the actor even if it's still running earlier instructions ie loops? For timers, particularly when you run after 'x' secs, do subsequent instructions also wait for that to occur or do they run anyway? If you add lets say 3 timers after each other, after 2 secs, after 3 secs and after 5 secs does the last timer trigger at 5 secs or 10 secs which is the total? And lastly, what are the effects of ticking or not ticking the run to completion check box. I've gone through the cookbook and it is not detail nor clear at times. Thanks folks

Comments

  • AlchimiaStudiosAlchimiaStudios Member Posts: 1,069
    edited June 2016

    @fmakawa

    Loops can iterate at a variable pace since recent changes. I believe a standard loop iterates every 1/60th of a second, or once per frame. Constrain is 1/60th as well.

    Other behaviors update every 1/30th of a second or once every other frame. I don't think we've been told how every behavior operates, but this is a good guideline.

    Things like spawn can iterate even slower then that, depending on how they are configured/how many are being called.

    Run to completion means even if the underlying conditions change the logic within, the timer will complete regardless.

    So it's useful for writing something like

    when attribute self.X = 0

    Timer after .5 run to comepletion
    Change attribute self.X to 1
    Change attribute self.Y to 1

    Because now even tho X is no longer meeting the rules conditions, it will finish that bit of logic and change the X and Y.

    I guess your asking if by the third it would trigger logic?

    As far as I can remember, 3 afters will result in the total number of seconds being reached of all timers. so after 2+3+5= 10 seconds to do logic or 5 to reach third timer.

    Follow us: Twitter - Website

  • SocksSocks London, UK.Member Posts: 12,822

    @fmakawa said:
    If you add lets say 3 timers after each other, after 2 secs, after 3 secs and after 5 secs does the last timer trigger at 5 secs or 10 secs which is the total?

    What happened when you tested this very easy to test idea ? :smile:

    (It triggers after 5 seconds)

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited June 2016

    Hi @fmakawa

    How long does GS take to process each bit of instructions...

    that is not really measurable, but, GS can do a LOT within one draw-frame (cycle), which is about 0.02 seconds.

    ... or run loops ...

    Pre 1.25, loops cycle only once per draw-frame, so a loop that cycles 50 times, will take at best one second to complete.

    With 1.25 you can now determine how many cycles a loop should complete within one draw-frame, greatly speeding up loops.

    ... or search tables?

    The table search function is part of the engine and very fast, so it can easily find a value in a large table, within one draw-frame.

    How long does GS take to process each bit of instructions or run loops or search tables? Does it continue running additional code in the actor even if it's still running earlier instructions ie loops?

    No, my understanding is, everything runs sequentially, GS does not run multi-threaded.

    For timers, particularly when you run after 'x' secs, do subsequent instructions also wait for that to occur or do they run anyway? If you add lets say 3 timers after each other, after 2 secs, after 3 secs and after 5 secs does the last timer trigger at 5 secs or 10 secs which is the total?

    The last timer runs after 5 seconds.

    GS is event driven. This is why code sometimes does not seem to run sequentially.

    In principle, you can think of it this way: When GS comes across a rule, it creates a little sticky, reminding itself to check every draw-frame if that rule has become true. If so, it executes the code with in.

    For this reason, timers can be seen in the same way as rules. A timer is just a rule being checked, has enough time passed for me to run my code.

    And lastly, what are the effects of ticking or not ticking the run to completion check box

    If you tick "run to completion", then you are forcing all the code within the timer to get executed. If you don't tick it, code execution may get stopped as soon as a higher level rule becomes false.

  • fmakawafmakawa Member Posts: 565

    I tried and nothing was panning out properly hence all the questions so I could truly understand. When you say it triggers after 5 seconds are you it start counting its own 5 secs after 5 secs a la @AlchimiaStudios or are you saying that it triggers it behaviours after 5 secs irrespective of the 2 timers before it?
    Lastly, because I noticed when I tested some behaviors seemed to trigger even though a timer before them wasn't finished- Do behaviour placed after a timer and not within it trigger after timer is done or occur anyway whilst the timer is doing is its thing?

    Thanks folks!

    @Socks said:

    @fmakawa said:
    If you add lets say 3 timers after each other, after 2 secs, after 3 secs and after 5 secs does the last timer trigger at 5 secs or 10 secs which is the total?

    What happened when you tested this very easy to test idea ? :smile:

    (It triggers after 5 seconds)

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2016

    @fmakawa said:
    I tried and nothing was panning out properly hence all the questions so I could truly understand. When you say it triggers after 5 seconds are you it start counting its own 5 secs after 5 secs a la @AlchimiaStudios or are you saying that it triggers it behaviours after 5 secs irrespective of the 2 timers before it?

    Make an actor - give it the rules you wish to test - and preview it to see how it responds.

    @fmakawa said:
    are you saying that it triggers it behaviours after 5 secs irrespective of the 2 timers before it?

    Yes. This stuff is really straightforward to test, I'm curious why this would even be a question ?

    @fmakawa said:
    Lastly, because I noticed when I tested some behaviors seemed to trigger even though a timer before them wasn't finished- Do behaviour placed after a timer and not within it trigger after timer is done or occur anyway whilst the timer is doing is its thing?

    Again, I'd make the same point that this stuff isn't really worth a question as it probably takes less time to test than to type out the question ! (which is one of the great things about GameSalad).

    Make an actor, give it a timer that displays "30" when 30 seconds is reached, also place a rule after that timer that does something obvious, like change the actor's size or colour (or whatever) - hit preview and share your findings ! . . . keep doing this and become a GameSalad expert !

  • fmakawafmakawa Member Posts: 565

    @Socks I asked because I had differing results. I have been using GS long enough to have taken certain things for granted and when things where not working the way the should I tested and it wasn't making sense- so I asked. That way I don't presume, use a work around and then find it not working as well later down the road. I was being thorough. Thanks for all the answers everyone.

  • SocksSocks London, UK.Member Posts: 12,822

    @fmakawa said:
    @Socks I asked because I had differing results.

    What were your results ?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    If you add lets say 3 timers after each other, after 2 secs, after 3 secs and after 5 secs does the last timer trigger at 5 secs or 10 secs which is the total?

    Scenario A

    Timer after 2 seconds
         Log Debugging Statement self.Time

    Timer after 3 seconds
         Log Debugging Statement self.Time

    Timer after 5 seconds
         Log Debugging Statement self.Time

    That should give you:
         2
         3
         5

    Scenario B

    Timer after 2 seconds
         Log Debugging Statement self.Time
         Timer after 3 seconds
              Log Debugging Statement self.Time
              Timer after 5 seconds
                   Log Debugging Statement self.Time

    That should give you:
         2
         5
         10

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • fmakawafmakawa Member Posts: 565

    Some behaviors were not triggering but only triggered after being placed in a timer. Some other behaviours didn't trigger when placed in a timer but triggered outside of it. There was no competing code that might have affected it. There was only one actor and I turned off/on behaviours plus log statements (heck some log statements weren't triggering which was my first clue - i posted something about it yesterday I think) till I narrowed down things. I have it working now but I wanted to know what could have been the cause hence the rather wide ranging questions however simple they may have been.

    @Socks said:

    @fmakawa said:
    @Socks I asked because I had differing results.

    What were your results ?

  • SocksSocks London, UK.Member Posts: 12,822

    @fmakawa said:
    Some behaviors were not triggering but only triggered after being placed in a timer. Some other behaviours didn't trigger when placed in a timer but triggered outside of it.

    Without seeing the code it's pretty much impossible to guess what the issue might be.

  • fmakawafmakawa Member Posts: 565

    I would have placed a demo but since I had fixed my issue and substantially altered things in actor as I moved on I would struggle to replicate the exact example of what it was like then. Missed opportunity- should have a saved a debug version for a demo.

    @Socks said:

    @fmakawa said:
    Some behaviors were not triggering but only triggered after being placed in a timer. Some other behaviours didn't trigger when placed in a timer but triggered outside of it.

    Without seeing the code it's pretty much impossible to guess what the issue might be.

  • SocksSocks London, UK.Member Posts: 12,822

    @fmakawa said:
    I would have placed a demo but since I had fixed my issue and substantially altered things in actor as I moved on I would struggle to replicate the exact example of what it was like then. Missed opportunity- should have a saved a debug version for a demo.

    No problem, glad you sorted it out.

  • NNterprisesNNterprises Member, PRO Posts: 387

    Probably unrelated, but this info in this thread helped me understand more about timers/loops and how things are processed:

    http://forums.gamesalad.com/discussion/92166/timer-vs-loop#latest

  • fmakawafmakawa Member Posts: 565

    Insightful discussion. definitely noted

    @NNterprises said:
    Probably unrelated, but this info in this thread helped me understand more about timers/loops and how things are processed:

    http://forums.gamesalad.com/discussion/92166/timer-vs-loop#latest

Sign In or Register to comment.