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

Comments

  • -Timo--Timo- Member Posts: 2,313
    both are possible :) use whatever you want. I don't think it makes any difference
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Too many nested rules get messy. Use the otherwise where you can but try not to nest more than one or two rules if you can help it.
  • richcoyrichcoy Member Posts: 211
    That's what I was thinking. I got to 7 nested rules and it got pretty ugly and difficult to manage. But I was willing to put up with it if it was the way to get the best performance. Thanks!
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    edited October 2013
    If you had 8 separate rules, every rule would have to be checked.

    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

  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Otherwise is absolutely the way to go.

    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
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited October 2013

    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

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    The others are dead wrong. Use separate rules* ;)


    * Kidding.
Sign In or Register to comment.