Use "Otherwise" or not?
In a game I'm developing I have a level count on screen that uses a game attribute to change the image to the current level. So a rule would look like "if game.level = 3 change image to level_3.png".
Should I be nesting the rules inside each other using the otherwise or should I just have each as a separate rule? Both ways work but I'm wondering from a performance standpoint if you gain anything from nesting them.
Rich
Should I be nesting the rules inside each other using the otherwise or should I just have each as a separate rule? Both ways work but I'm wondering from a performance standpoint if you gain anything from nesting them.
Rich
Comments
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
If you use nested rules, and let's say it's level 1, then the list of nested rules underneath won't have to be checked. As the first rule, when level=1, is valid the engine will not then try and go to the next rule.
So in this case having nested rules is faster.
I think the way GS works is that every rule is automatically checked every cycle. So having a lot (thousands) of rules in a project means you get a lower frame rate as these rules are all constantly being checked at run time.
When on level 8, the engine will have to check through all the way until it gets to the last rule. As when level= 1 and when level = 2 etc are not valid. So in this case, having nested rules would probably be the same speed as having 8 separate rules.
But for relatively small projects it probably doesn't matter either way in terms of performance. Current GS + current smart phones are pretty good.
If your game works as you want and it plays well.. then it's all good!
And just a small note - if you including ".png" as part of your rule you don't need to. And it's better not to as there is support for different image types coming down the road. Also it takes longer to type!
Edit: Another note - you only need 1 rule at all.
When the level change is triggered have game.levelSwitch change from 0 to 1.
Then your rule would be:
When game.levelSwitch is 1
Change self.image to table(myTable, game.level, myColumnForImageNames)
Then as the last rule in your last actor (at the top of your layers list) have:
when game.levelSwitch 1
change game.levelSwitch to 0
Ive nested in like 40-50 rules before. Performance is better by far. Yes it's messy on the developer side but in the published so its absolutely 100% better.
Cheers
Aaron
Yes, agree with the other guys as well, Otherwise is fine and when needed is necessary anyway for programming... also nesting is fine... but they are two different things really, i.e you can't replace Otherwise stuff with nesting, for instance (well, you can, in some situations, but they are still nicely separated things, Otherwise and nesting, both needed, if you see what I mean... )
So it's whatever is needed at the time, and gets the job done the most efficiently. :-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
* Kidding.
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx