Lots of Rules vs. lots of otherwise? performance

StormtrixStormtrix Member Posts: 256
edited November -1 in Working with GS (Mac)
Hey all,
was just updating my Blind Man's Bluff card game and was thinking -
for randomizing one card and then deciding what image to show for the random number, does it matter from a performance view if you chose one way or the other?

For instance -
Change attribute/ game.card to random(0,52)

Rule if game.card = 12
use this card

Rule if game.card = 13
use this card

and so on.....

or just make 1 rule and put 52 otherwises in it.

thank you,
and happy holidays

Comments

  • UtopianGamesUtopianGames Member Posts: 5,692
    I would always try and use lots of otherwise instead of lots of rules.

    The only problem i can see is with you having 52 the rule box will get pretty small as it shrinks every time you do a new otherwise.

    Darren.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Maybe your example is just hypothetical, but you can just use the change attribute behavior to change the actor's image to "card"..game.card..".png" as long as your images are named to match...
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Like bark said i would use a change image for each card and then have a attribute called cardvalue or whatever and have that constrained to the random number pulled so its the same actor but the value changes to the number
  • frariofrario Member Posts: 164
    I did it and not only the box gets small, but the loading times keep increasing. I had to close and restart gamesalad very often to keep working. However your one could be lighter, since (for what I can tell) you don't care about repetitions.

    If that's the case, you could simply go as BarkBarkCo suggested. You only need two rules!

    Otherwise seems better to me using "otherwise" than separate rules in terms of performance.
  • StormtrixStormtrix Member Posts: 256
    Thanks guys for the replies, it really helped.
    I went from having 52 rules to just 1 !!

    First I made the file name my 52 cards random numbers between 1-52 like.
    2Hearts.png is now 24.png, 3Clubs.png is 14.png, KClubs.png is 7.png, etc...

    then just did this

    Timer - Every .001 sec -
    change attribute: game.randomcard To: random(1,52)

    Rule - When touch is pressed ( on back of card )
    Change Attribute : game.card To: game.randomcard
    Change Attribute: self.image To: floor(game.card)..".png"

    Done.

    Appreciate the help again!
    Merry Christmas
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    merry christmas! :)
  • UtopianGamesUtopianGames Member Posts: 5,692
    Doing it that way could result in 2 or more of the same cards?

    Darren.
Sign In or Register to comment.