10 Rules of otherwise - performance question

StormtrixStormtrix Member Posts: 256
edited November -1 in Working with GS (Mac)
Morning -
Just curious if this really matters --

If you have 10 rules like the below example -which way is better to implement them or does it really matter??

Rule #1
If game.attribute = 1
Play sound 1
-otherwise-
Rule #2
If game.attribute =2
Play sound 2
-otherwise-
Rule #3
If game.attribute =3
Play sound 3

and so on to 10

** OR **

just list 10 separate rules

Rule #1
If game.attribute = 1
Play sound 1

Rule #2
If game.attribute =2
Play sound 2

Rule #3
If game.attribute =3
Play sound 3

and so on to 10

thx

Comments

  • crazyfishdevcrazyfishdev Member Posts: 283
    You want the second one... The first one wont work <><
  • StormtrixStormtrix Member Posts: 256
    sure it will crazy.. i've had it work before actually.
  • StormtrixStormtrix Member Posts: 256
    thx tshirt..
  • firemaplegamesfiremaplegames Member Posts: 3,211
    the first one.

    the second one will needlessly read all the rules, even when a condition has been met.
  • crazyfishdevcrazyfishdev Member Posts: 283
    sry missed the rules under the otherwise... my bad yea it will work with the rules in place
    (thats what you get for posting just when you wake up :) )
  • heathccheathcc Member Posts: 113
    Is there a performance benefit to either?

    I'm not smart enough to nest Otherwise statements too far without ripping my hair out. Well, what it left of it.

    H
  • hackmodfordhackmodford Member Posts: 48
    The otherwise statements will save on performance because if the first one is true it won't bother computing the rest...

    So if 1 is true it doens't check the 9 other If Statements...
    If 1 is false then it checks if 2 is true... if that one is it doesn't need to check the rest, and so on.

    So yes the first 1 is a better choice as long as you don't want 1 and 2 to be true at the same time...
Sign In or Register to comment.