No timers does save time... a lot!

LumpAppsLumpApps Member Posts: 2,881
edited November -1 in Working with GS (Mac)
Hi,
To bring up an old subject. I am working on a project and in the menu I had lots of timers.
Yesterday I worked all day to get them out and replace them by either self.time or interpolate selfmade time attributes. I thought it would only win me processor time but the decrease of loading time is incredible.
IBefore the menu there is an intro and when I had timers and went from intro to menu it took about 7 seconds at least.
Now without the timers it takes about 2 seconds. Awesome!

So for the ones with doubts, I believe no timers is the way to go!

Comments

  • old_kipperold_kipper Member Posts: 1,420
    Sounds very good. Would you be kind enough to detail the self.time and selfmade time attributes you are using to replace the timers.

    thanks kipper
  • LumpAppsLumpApps Member Posts: 2,881
    Sure:

    After 0.2 sec timer:
    Make a (self) attribute named timer

    Interpolate
    self.timer to 1
    Duration 0.2

    Rule
    when atribute self.timer = 1
    [do something]
    interpolate self.timer to 1
    Duration 0.001 [as small as posible, 0 doesn't work because it sometimes crashes]

    Instead of an after x seconds timer in the beginning of a scene you can use a rule:

    Rule
    when attribute self.time = x
    [do something]

    or
    Rule
    when attribute self.time > x
    do something

    Every 1 second timer:
    Make a timer attribute
    Rule
    when timer = 1
    interpolate timer to 0
    Duration 0.001 second

    otherwise
    interpolate timer to 1
    duration 1 second

    Rule
    when self.time = 1
    do something

    Sometimes self.time = 1 in the 'every' time is not triggering (probably because self.time is 1 for a very short time). You can also use when self.time > 0.5 because self.time is > 0.5 for a longer time then it is 1.

    Hope this makes sense.

    Cheers!
  • old_kipperold_kipper Member Posts: 1,420
    Cheers. I've done similar to your first example, but not the second. There is a project I have with 50 interpolates on timers running and this may well help...
  • LumpAppsLumpApps Member Posts: 2,881
    The most trouble I had was go back to the initial value. Because interpolate can't be stopped.
    When you would use change to get back to the initial timer value in the "when timer = 1" rule the interpolate value to 1 wasn't finished when it was 1. So the change attribute would change it to 0 and the interpolate would change it back to 1 although the interpolate should already have stopped when the value was 1.
    That is why I interpolate back to 0 instead of change. While the initial interpolate might not be ready the second will always change it to 0.

    Hope this makes sense ;)
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    @ Ludwig:

    Do you need to use interpolate at all? I suppose it depends on the context but when I had a lot of moving objects on the screen I found additional interpolates (of colour,size etc) tended to punch the frame rate in the face.

    Have you tried the following?

    Create a real attribute game.timeStamp
    Create a real or index attribute game.duration with your chosen period of seconds. In this example 2.
    Create an index attribute called zero with value 0

    To replace an 'after' timer:

    RULE
    When your event happens
    Change game.timeStamp to game.time

    RULE
    When game.time is more than/equal to game.timeStamp + game.duration
    ... do yo' thang

    To replace a 'for' timer:

    RULE
    When your event happens
    Change game.timeStamp to game.time

    RULE
    When game.time is less than/equal to time.stamp + game.duration
    … do the hockey pockey

    To replace an 'every' timer:

    (every 2 seconds)
    RULE
    When game.zero = game.time%2
    ... do the Bart (man)

    (every 1 second)
    RULE
    When game.zero = (game.time*2)%2
    ... do the right thing

    (every 0.5 seconds)
    RULE
    When game.zero = (game.time*4)%2
    ... do what you do best

    Shaz

    ------------
    image
    "...the resulting sonic effect is almost mesmerising." Pocket Gamer
    Sound design and music service available: http://tiny.cc/MusicService
    www.HoneyTribeStudios.com
  • LumpAppsLumpApps Member Posts: 2,881
    Ah, very good!
    In my current game I have not a lot of moving objects so I don't have a frame rate problem (it is around 60 most of the time anyway).
    Because my method uses only one attribute it was easier to implement (and I am a bit lazy sometimes) but I see a lot of advantages in yours.
    Thanks for sharing!

    Cheers,
    Ludwig
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    how about using the device clock..instead of game time...

    can't think what the benefit would be... just throwing it out there...

    you could use a similar setup to my loading times timer...its a bit annoying to use in that the seconds loop when they hit 60 so you have to track if the minutes change and do any offset...(same for milli seconds and seconds etc)
  • old_kipperold_kipper Member Posts: 1,420
    I feel cheated! Why have GS not implemented the long awaited behaviours that Shaz has custom coded? If do yo' thang/the hockey pockey/Bart(man)/right thing/what you do best, are not in the next update I may have to switch SDK.

    kipper
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    kipper...your not going to quit..

    its still in beta.

    Loading times will improve..

    In app purchasing is coming.

    Android support too..

    Things are bright... and still no complicated coding...just far less complicated maths and rules instead.
  • old_kipperold_kipper Member Posts: 1,420
    I jest... I just loved Shaz's examples
  • LumpAppsLumpApps Member Posts: 2,881
    stormystudio said:
    how about using the device clock..instead of game time...

    can't think what the benefit would be... just throwing it out there...

    you could use a similar setup to my loading times timer...its a bit annoying to use in that the seconds loop when they hit 60 so you have to track if the minutes change and do any offset...(same for milli seconds and seconds etc)

    So seconds loop? This could be used for an every timer then I guess?
    Have to figure out how but If the seconds are 60 every 60 seconds (makes sense) then you could use this when used with a modulator for avery value below 60 seconds...

    Sorry if thats wrong, I have just recently discovered how the math I learned in school works ;)
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    old_kipper said:
    I feel cheated! Why have GS not implemented the long awaited behaviours that Shaz has custom coded? If do yo' thang/the hockey pockey/Bart(man)/right thing/what you do best, are not in the next update I may have to switch SDK.

    kipper

    When I upgraded I had the hockey pockey options in the pro behaviours list. Didn't you? Unfortunately one time it got stuck in a loop when I accidentally set it to 'every 0.1 seconds'. My left leg has never recovered.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    :-)

    yeah...you could have rules

    For every second:

    if device, clock, milli seconds = 1 (or you could use any number between 0 and 999)
    then do something

    for every ten seconds
    if any:
    device, clock, seconds = 0
    device, clock, seconds = 10
    device, clock, seconds = 20
    device, clock, seconds = 30
    device, clock, seconds = 40
    device, clock, seconds = 50
    device, clock, seconds = 60
  • old_kipperold_kipper Member Posts: 1,420
    HoneyTribeStudios said:
    When I upgraded I had the hockey pockey options in the pro behaviours list. Didn't you? Unfortunately one time it got stuck in a loop when I accidentally set it to 'every 0.1 seconds'. My left leg has never recovered.

    In my cheap and pitiful life of pre pro license I use booleans to trigger a custom simple in/out self arse kicking behaviour. Effective, but oh how I wish for the pro hockey pockey with drag n drop left leg in, left leg out.
  • Rob2Rob2 Member Posts: 2,402
    Making use of Modulo (%) is a way of making simple timers but it stills uses a rule so I don't know if it is better than a timer.

    image

    If game.clk is an attribute with value 3 then Help! will flash up every 3 seconds.
  • LumpAppsLumpApps Member Posts: 2,881
    Apparently rules take up less processor time then timers. So it would help.
  • LamthalasLamthalas Member Posts: 5
    Shaz, is the ≥ the same as Run to Completion?
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    Lamthalas said:
    Shaz, is the ≥ the same as Run to Completion?

    No it's not the same, it means more than or equal to.

    Unless I've misunderstood your question?

    The technique I posted above does not include something that duplicates the 'run to completion' check box in timer behaviours.
  • LamthalasLamthalas Member Posts: 5
    Ahh...ok. I was just wondering why you're using that instead of =. By the way, isn't it much faster to just type in the duration in the expression field like: game.timeStamp + 1 (or +2 for 2 sec, etc..) instead of create a duration attribution which takes quite a bit of time to select if you got a lot attributes?
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    Lamthalas said:
    Ahh...ok. I was just wondering why you're using that instead of =. By the way, isn't it much faster to just type in the duration in the expression field like: game.timeStamp + 1 (or +2 for 2 sec, etc..) instead of create a duration attribution which takes quite a bit of time to select if you got a lot attributes?

    The reason to use more than or equal to is because of how GS works. e.g if an actor is moving and you tell it to stop at a certain point - it won't stop at the exact pixel location every time. So if you just use '=' sometimes your behaviours will not trigger. But it depends on the context.

    Generally it's better to use attributes. This will probably save you time as you develop you game.

    Rather than clicking through all the actors when you want to make changes it's much quicker to have a list of attributes on the same page that you can change quickly.

    e.g you might have a set of actors that move at the same speed, or have the same initial hit points or whatever.

    You'll probably be adjusting those figures as you develop the game, finding out which values make the game feel right.

    If you have to double click every actor and every instance of an actor, find the values and change them one by one - that takes longer. Especially as a game gets bigger and more complex.

    Shaz

    ------------
    image
    "...the resulting sonic effect is almost mesmerising." Pocket Gamer
    Sound design and music service available: http://tiny.cc/MusicService
    www.HoneyTribeStudios.com
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    By the way, just so people don't have problems with the above stuff...

    If you're using small increments of time wrap the equation in a floor function otherwise it might not work properly.

    So for 0.1 seconds
    when game.zero = floor((game.time*20)%2)
    ... HEEEEY Macarena!
Sign In or Register to comment.