Basic OR logic with 3 choices?

3absh3absh Member Posts: 601

I have 3 music soundtracks in my game, I want them to play randomly while playing
I'm assuming the 1st random number here is different from that of the 2nd random number

So I'm pretty sure this logic will not work,
How can I set up a logic where I make 1 random choice out of more than 2, maybe 4 or 5 choices to turn ON every time the music ends?

Comments

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    Have an attribute called randomNumber and then set that with Change Attribute i.e.

    Change Attribute: self.randomNumber = random(1, 5)

    Then have a rule like you have for each randomNumber i.e.

    If self.randomNumber = 1
    Play music 1

    If self.randomNumber = 2
    Play music 2

    etc...

  • ArmellineArmelline Member, PRO Posts: 5,369

    That logic won't work as the two rules will generate two different random numbers. Both could be 0, both could be 1, or they could be different.

    You want to make a new integer attribute, and change it to random(1,3), and then have your conditions using that.

    if integer = 1 play song 1
    if integer = 2 play song 2
    if integer = 3 play song 3

  • 3absh3absh Member Posts: 601

    Ok excellent guys,
    but how do I make the next track play when the previous one ends?

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @abuabed84 said:
    Ok excellent guys,
    but how do I make the next track play when the previous one ends?

    That you need to do with a timer.

  • 3absh3absh Member Posts: 601

    @The_Gamesalad_Guru said:
    That you need to do with a timer.

    I thought about that but problem is not all tracks are the same lenths

  • KevinCrossKevinCross London, UKMember Posts: 1,894

    Something like this maybe:

    If self.randomNumber = 1
    Play music 1
    Timer: After 60 seconds
    Change Attribute: self.randomNumber = random(1, 5)

    If self.randomNumber = 2
    Play music 2
    Timer: After 90 seconds
    Change Attribute: self.randomNumber = random(1, 5)

    Change each timer to match the length of the music being played in the rule.

  • 3absh3absh Member Posts: 601

    @KevinCross said:
    Something like this maybe:

    If self.randomNumber = 1
    Play music 1
    Timer: After 60 seconds
    Change Attribute: self.randomNumber = random(1, 5)

    If self.randomNumber = 2
    Play music 2
    Timer: After 90 seconds
    Change Attribute: self.randomNumber = random(1, 5)

    Change each timer to match the length of the music being played in the rule.

    Excellent, I'll give it a try

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @abuabed84 said:
    I thought about that but problem is not all tracks are the same lenths

    I built an app for a client that used tables to store the sound file lengths (I had to check each file individually to determine this) and then could use the table values to know when a sound had completed. It's tedious to set up but works great.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.