And/Or

Im trying to figure out is there a way to have some kind of and/or statement in gamesalad? I am trying to make the player lose a health bar if certain things happen. For example, there are 7 numbers, a random number is picked and shown the player. If the player picks the correct number they get a point, if not they lose a health bar. I have it coded for if the player picks anything higher than the #1 and the random # equals 1. But what about once I get to 2-7? How do i tell gamesalad to only take away health, if the random # is 2, and the chosen # is > 2 and or = 1.

Comments

  • tintrantintran Member Posts: 453
    edited August 2015

    you can use expression like this
    (self.chosen == self.random) and 1 or -1
    this way when chosen number is equal to random number you get a 1 else you get a -1

    or if you have a point and health attribute you can do change attribute
    self.point to self.point + ((self.chosen == self.random) and 1 or 0)
    self.health to self.health + ((self.chosen != self.random) and -1 or 0)
    so when chosen = random you get 1 else 0 for point
    and when chosen not equal to random you get -1 health else 0.

    or you could just have a rule that checks if chosen == random
    and set point = point+1
    else
    set health = health - 1

  • colandercolander Member Posts: 1,610
    edited August 2015

    You can use conditional expressions in the expression editor to set/change an attributes value and they can be nested. Google "Lua and or" to learn more about them an how to use them.

  • GamingtilDawnGamingtilDawn Member Posts: 104

    @tintran Thanks alot! Just from the first part of your post I immediately figured it out. I don't even want to tell how much unnecessary code I had in this. I went from like 15 different boxes to just 4 lol.

  • GamingtilDawnGamingtilDawn Member Posts: 104

    @colander I actually want to learn about Lua. I had no idea it could be tied to GS.

  • tintrantintran Member Posts: 453
    edited August 2015

    @GamingtilDawn said:
    tintran Thanks alot! Just from the first part of your post I immediately figured it out. I don't even want to tell how much unnecessary code I had in this. I went from like 15 different boxes to just 4 lol.

    yeah you can do nested ands too like for example (just fictional case) if you wanted 1 point for matching ones, and 4 points for matching 2s and 8 points for matching 3s. you can do something like
    ((self.chosen == self.random) and (self.chosen == 1)) and 1 or
    ((self.chosen == self.random) and (self.chosen == 2)) and 4 or
    ((self.chosen == self.random) and (self.chosen == 3)) and 8 or
    0

Sign In or Register to comment.