Timers are for chumps - GS optimization tips

1246

Comments

  • allornothingallornothing Member, PRO Posts: 126
    This is gold. Thanks for the great breakdown and information. I really want to highlight how valuable this kind of information is, compared to the endless torrent of paid-for templates. Sell games, share information.
  • SocksSocks London, UK.Member Posts: 12,822
    @tatiang okay that makes sense! I'm always logged in on my iPad but safari Mac never keeps me logged in. Mystery solved.
    Same deal here, my iPad stays logged into the forums, while my Mac struggles to stay logged in, sometimes it can log in for a few minutes, sometimes it can't log in for hours at a stretch, so I now use my iPad for these forums.
  • dr2391dr2391 PRO Posts: 78
    So I am converting my game using these methods but I have a problem. This is my code

    when scene.time >5 and scene.time <6

    when self.mod1>self.time%.45

    change attribute game.currentNumber to random(1,4)

    when game.currentNumber = 1 or game.currentNumber = 2 or game.currentNumber = 3

    spawn actor1

    game.currentNumber = 4

    spawn actor 2



    So basically im spawning random actors for 1 second every .45 seconds and it works well. I was using timers before and they worked well but I wanted to switch to gain performance. It will spawn every .45 seconds like the old way but sometimes it will spawn 2 actors on top of each other. Im not sure what is causing this
  • dr2391dr2391 PRO Posts: 78
    anyone?
  • domeniusdomenius Member Posts: 108
    @dr2391 upload your project somewhere and pm me the link, I'll take a look at it.
  • allornothingallornothing Member, PRO Posts: 126
    Not sure what would cause duplicate spawning, but maybe put a destroy collision on them so if they collide with each other (or spawn on top of another) they'll both be removed. Not really a solution but a workaround potentially for now
  • dr2391dr2391 PRO Posts: 78
    @allornothing that wouldnt work because the enemies need to be able to cross each other. my game is already free on the app store if you want to take a look.
    iPad http://bit.ly/W5Cukt

    iphone http://bit.ly/10XsuOe

    android http://bit.ly/WmiIRf
  • ericzingelerericzingeler Member Posts: 334
    @dr2391

    I notice you have: when scene.time >5 and scene.time <6

    so you only want the rule valid between 5 and 6 seconds?

  • ericzingelerericzingeler Member Posts: 334
    Also,

    With:

    when game.currentNumber = 1 or game.currentNumber = 2 or game.currentNumber = 3

    Drop it all into one rule: game.currentNumber < 4
  • dr2391dr2391 PRO Posts: 78
    edited February 2013
    yeah when scene.time >5 and scene.time <6 is my replacement for a "for 1 second" timer

    and your second suggestion is a good one. Do you think this could possibly be the culprit? Because I have probably over 100 of these rules. Its basically how my game works, so i would have to go through and change every one. Thats fine if there is a benefit, do you think there is?
  • dr2391dr2391 PRO Posts: 78
    edited February 2013
    also, why does html not work on my posts? lol i try to start a new paragraph and it just shows the < br/> instead?
  • ericzingelerericzingeler Member Posts: 334
    oh ok... unfortunately it won't work that way. Check out my earlier post on page 3, let me know if you have questions.
  • dr2391dr2391 PRO Posts: 78
    Im not sure what that does
  • ericzingelerericzingeler Member Posts: 334
    Think you may be messing the the html tags by using the angle brackets in the description of your rules.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,948
    Think you may be messing the the html tags by using the angle brackets in the description of your rules.
    Yep, < and > are used to designate vanilla forums code.

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,948
    I've updated the Study of Loops file to include an Accelerate loop actor. It's far from perfect as it requires some fine tuning to work properly (the version in the file works pretty well from counter=1 to 200) and it's not as fast as an Every 0 timer loop. Still, I think it's interesting to consider another way to create a loop!

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

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2013

    Interesting and useful test file, thanks v.m, @tatiang :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,948
    Added a toggle loop actor that is as fast as the time stamp method. It does, however, require that rules/behaviors that run at each iteration are listed twice (see actor's notes).

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

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,877
    @tatiang -- you should try the implementation I suggested in my last post in this thread (January 28). It is twice as fast as the 'toggle loop' method. It is a variation (a simplification if you will) of the @ericzingeler 'time stamp' method. And it reaches the theoretical limits that GS timing can do (which is about 60 frames a second).


    When self.Time > self.oldTime
    -- Change Attribute: self.counter To: self.counter + 1
    --Change Attribute: resetOldTime To: true

    When resetOldTime is true
    -- Change Attribute: self.counter To: self.counter + 1
    -- Change Attribute: self.oldTime To: self.time
    -- Change Attribute: resetOldTime To: false
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,948
    @RThurman, sorry I thought that was the TimeStamp method but I see it's a bit different. Okay, I'll try it, thanks!

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,948
    edited March 2013
    Hot damn! That's the best one of all. B-) Okay, my Study of Loops is officially complete. Thanks to everyone who contributed ideas to the process!!!

    Here's the final version that includes the OldTime Loop.

    I also made it so that each loop counter display actor blinks when the loop is completed. This is handy because there's now a "Loop is complete" rule in each actor that can be used to add rules when the loop has done its job.

    For some reason, the mod1 Loop is broken. I'm not going to invest more time on it because the OldTime Loop is the proven winner (unless you count the black magic of the Spawner Loop >:) ).

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

  • ericzingelerericzingeler Member Posts: 334
    @tatiang -- you should try the implementation I suggested in my last post in this thread (January 28). It is twice as fast as the 'toggle loop' method. It is a variation (a simplification if you will) of the @ericzingeler 'time stamp' method. And it reaches the theoretical limits that GS timing can do (which is about 60 frames a second).


    When self.Time > self.oldTime
    -- Change Attribute: self.counter To: self.counter + 1
    --Change Attribute: resetOldTime To: true

    When resetOldTime is true
    -- Change Attribute: self.counter To: self.counter + 1
    -- Change Attribute: self.oldTime To: self.time
    -- Change Attribute: resetOldTime To: false
    Ah, nice. This makes much more sense. Good work @RThurman
  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2013
    @tatiang

    Could you not simply place as many 'functions' (the thing you want the loop to do/increment) into the rule ?

    Maybe I'm missing something obvious, but with multiple functions you can get much higher iteration rates ? For example (appologies for a quick and messy hacking of your file !! 8-X ) this 'X' rule lays out 500 randomly coloured squares in under 2 seconds.

    Am I missing something basic here ??
  • domeniusdomenius Member Posts: 108
    @socks I was going to mention that exact workaround. It leads to messy code that is difficult to maintain, but it definitely works. I've used the technique myself.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,948
    Good point, @Socks. But I would have expected a prettier picture.

    Alright so the study continues... lol

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

  • SocksSocks London, UK.Member Posts: 12,822
    @socks I was going to mention that exact workaround. It leads to messy code that is difficult to maintain, but it definitely works. I've used the technique myself.
    Yeah, agreed, the code is not very elegant with loads of functions crammed in one after another - but if you wanted to iterate lots of things very quickly it's useful as an idea.
  • SocksSocks London, UK.Member Posts: 12,822
    Good point, @Socks. But I would have expected a prettier picture.

    Alright so the study continues... lol
    Yeah, I'm not going to win the 2013 GS Demo contest with that one ! :)

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,948
    edited March 2013
    Using the "X" method, how would you stop the loop at a certain iteration? Your example loops in multiples of ten, I believe, but if you have 32 table rows that you are looping through, how can you stop it at 32 iterations (without putting a When counter<rowCount rule on every single "function")?

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

  • SocksSocks London, UK.Member Posts: 12,822
    Using the "X" method, how would you stop the loop at a certain iteration?
    I'd simply ask tatiang on the GameSalad forums.
  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2013
    Using the "X" method, how would you stop the loop at a certain iteration? Your example loops in multiples of ten, I believe, but if you have 32 table rows that you are looping through, how can you stop it at 32 iterations (without putting a When counter

    Place a max iterations check after every single "function".

    ;P

    Or pre-calculate what you need and construct accordingly.
Sign In or Register to comment.