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.
@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.
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
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
@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
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?
tatiangMember, Sous Chef, PRO, Senior Sous-ChefPosts: 11,949
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!
tatiangMember, Sous Chef, PRO, Senior Sous-ChefPosts: 11,949
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).
@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
tatiangMember, Sous Chef, PRO, Senior Sous-ChefPosts: 11,949
@RThurman, sorry I thought that was the TimeStamp method but I see it's a bit different. Okay, I'll try it, thanks!
tatiangMember, Sous Chef, PRO, Senior Sous-ChefPosts: 11,949
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 >:) ).
@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
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.
@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.
tatiangMember, Sous Chef, PRO, Senior Sous-ChefPosts: 11,949
Good point, @Socks. But I would have expected a prettier picture.
@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.
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 !
tatiangMember, Sous Chef, PRO, Senior Sous-ChefPosts: 11,949
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")?
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.
Comments
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
iPad http://bit.ly/W5Cukt
iphone http://bit.ly/10XsuOe
android http://bit.ly/WmiIRf
I notice you have: when scene.time >5 and scene.time <6
so you only want the rule valid between 5 and 6 seconds?
With:
when game.currentNumber = 1 or game.currentNumber = 2 or game.currentNumber = 3
Drop it all into one rule: game.currentNumber < 4
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?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
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
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 ??
Alright so the study continues... lol
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User