Accessing a second entry in a table to play a sound

Hi,

I ma working with tables at the moment whereby when an event is called, it selects a random item from a column and displays the text on-screen. This works fine, no problem at all. However, my issue at the moment is that I want it to play a specific sound at the same time; so if entry 1 was selected, it would play sound A, entry 3 would play sound C for example.

Does anyone have any suggestion how to go about this?

Many thanks in advance!

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2014
    There is currently no way to select a sound by using an expression, so the only way is to manually set up a rule for each possible value and possible sound:

    When attribute game.columnValue=1
         Play sound [sound file A]

    When attribute game.columnValue=2
         Play sound [sound file B]

    When attribute game.columnValue=3
         Play sound [sound file C]

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

  • bryanearlbryanearl Wasilla, AlaskaMember, PRO Posts: 49
    This is just one method...

    First, you may have to add a rule to your event where, along with displaying the text, you also set an attribute (integer) to whatever the random number chosen is. We will call this "random_item_number" for now...

    Once you have an attribute that now will always contain the current "random" number, you could create an invisible actor (or just off-screen) that "watches" for this event you described above. Make rules on your new invisible actor that state:

    "When 'random_item_number' = 0, DO NOTHING"

    "When 'random_item_number' = 1, play sound XXXX and then Set 'random_item_number' back to 0"

    "When 'random_item_number' = 2, play sound XXXX and then Set 'random_item_number' back to 0"

    etc...

    The "and then Set 'random_item_number' back to 0" is to prevent any sounds from being played more than once by accident.

    NOTE - Technically, you would not need to actually have a rule stating to "DO NOTHING"... I just put that there for a reference. Whenever the attribute = 0, unless stated otherwise, it would "do nothing" anyway.

    Does that make sense/help?
  • DaveGWelshDaveGWelsh Member Posts: 60
    Hi tatiang,

    This approach was what I tried to do, however I can't seem to access the table value from the rule.

    Is it actually possible?
  • DaveGWelshDaveGWelsh Member Posts: 60
    This is just one method...

    First, you may have to add a rule to your event where, along with displaying the text, you also set an attribute (integer) to whatever the random number chosen is. We will call this "random_item_number" for now...

    Once you have an attribute that now will always contain the current "random" number, you could create an invisible actor (or just off-screen) that "watches" for this event you described above. Make rules on your new invisible actor that state:

    "When 'random_item_number' = 0, DO NOTHING"

    "When 'random_item_number' = 1, play sound XXXX and then Set 'random_item_number' back to 0"

    "When 'random_item_number' = 2, play sound XXXX and then Set 'random_item_number' back to 0"

    etc...

    The "and then Set 'random_item_number' back to 0" is to prevent any sounds from being played more than once by accident.

    NOTE - Technically, you would not need to actually have a rule stating to "DO NOTHING"... I just put that there for a reference. Whenever the attribute = 0, unless stated otherwise, it would "do nothing" anyway.

    Does that make sense/help?
    Ah, this makes sense!!! Yes, i'll give it a go.

    Thanks!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2014
    I can't seem to access the table value from the rule.

    Is it actually possible?
    Yes, but you have to do a slight workaround. First change or constrain game.columnValue to tableCellValue(tableName,row,col) and then use game.columnValue in your rules. You can't use a table expression on the left side of a rule... though this is coming in the next version of GameSalad Creator.

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

  • DaveGWelshDaveGWelsh Member Posts: 60
    Ok, this worked! Thanks soooo much!!!
  • bryanearlbryanearl Wasilla, AlaskaMember, PRO Posts: 49
    Pimpin since pimpin been pimpin! hehe, glad it worked.
Sign In or Register to comment.