Question regarding displaying random text from a collection of different tables

ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296
edited February 2014 in Working with GS (Mac)
Hi guys

I have a question regarding tables...

I have a joke app where I have a series of different joke types, linked to their own table.

I have on the joke select screen a button called 'RANDOM'.

when you click on this it goes to a scene where I have display actor...

How do I get this to display random test from any of 6 tables...so when the user clicks the forward button it goes and randomly picks any joke from any of the 6 tables I have?

I also need to to remember the previous joke in case the user presses the back button

Thanks all

It takes a Zombie to know a Zombie!!!

Comments

  • ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296
    edited March 2014
    Anyone know how to display a random row on a random table if a button is pressed?

    It takes a Zombie to know a Zombie!!!

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    Here's what you could do...

    The way you've set it up is interesting, but let's take a crack:

    Create a boolean attribute - name it GrabQuote, or something like that.
    Create an integer attribute - name it WhichTable - set it to 0 initially
    Create a text attribute - name it DisplayQuote, or something like that

    When they touch the button, change that attribute to true.

    When it's true, in a separate actor, have something like this:
    Rule: When game.GrabQuote is true,
    Change attribute: game.WhichTable to random(1,6)

    Then you'll need to create more rules:

    Rule: When game.GrabQuote is true AND when game.WhichTable = 1
    Change attribute: game.DisplayQuote to tableCellValue(Table1,tableRowCount(Table1),1)

    Rule: When game.GrabQuote is true AND when game.WhichTable = 2
    Change attribute: game.DisplayQuote to tableCellValue(Table2,tableRowCount(Table2),1)

    And so on - what this does is the first attribute we're changing, gameGrabQuote, grabs a value from 1 to 6 since you have 6 tables.

    When that attribute is true, and when the game.GrabQuote = X, grab a value from X table.

    Hopefully that makes sense. Obviously there's more rules that need to be added and stuff, but hopefully that gets you on the right track.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited March 2014

    Hi @Zombiebrains as long as you're not worried about duplication, that's really straightforward.

    Make two integer game attributes, lets call one RandTable and the other RandRow

    In the Rules of your button called RANDOM, put:

    When touch is pressed
    Change Attribute RandTable to random(1,6)
    Change Attribute Randrow to random(1,30) --- 30 is just an example of max. amount of rows in any one table
    Change Scene ShowJoke -- or whatever your scene is called with the Display Text on it

    --Before I mention the next bit, if there are different amounts of rows in all the 6 tables, then you need the Rules a bit differently:

    When touch is pressed
    Change Attribute RandTable to random(1,6)
    When Attribute RandTable = 1
    Change Attribute Randrow to random(1,30) --- 30 is just an example of max. amount of rows in table 1
    When Attribute RandTable = 2
    Change Attribute Randrow to random(1,35) --- 35 is just an example of max. amount of rows in table 2
    --etc up to RandTable = 6
    Change Scene ShowJoke -- or whatever your scene is called with the Display Text on it

    ---

    Now in your actor showing the Display Text behaviour, amend to:

    When RandTable = 1
    Display Text tableCellValue(yourTable1,Randrow,1)
    Otherwise
    When RandTable = 2
    Display Text tableCellValue(yourTable2,Randrow,1)
    Otherwise
    When RandTable = 3
    Display Text tableCellValue(yourTable3,Randrow,1)
    Otherwise
    ---etc up to When RandTable = 6

    Edit: Bray beat me to it!

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    @gyroscope‌ >:)
    Ha! B-) :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • ZombiebrainsZombiebrains www.zombiebrains.co.ukMember, PRO Posts: 296

    @gyroscope said:
    Hi Zombiebrains as long as you're not worried about duplication, that's really straightforward.

    Make two integer game attributes, lets call one RandTable and the other RandRow

    In the Rules of your button called RANDOM, put:

    When touch is pressed
    Change Attribute RandTable to random(1,6)
    Change Attribute Randrow to random(1,30) --- 30 is just an example of max. amount of rows in any one table
    Change Scene ShowJoke -- or whatever your scene is called with the Display Text on it

    --Before I mention the next bit, if there are different amounts of rows in all the 6 tables, then you need the Rules a bit differently:

    When touch is pressed
    Change Attribute RandTable to random(1,6)
    When Attribute RandTable = 1
    Change Attribute Randrow to random(1,30) --- 30 is just an example of max. amount of rows in table 1
    When Attribute RandTable = 2
    Change Attribute Randrow to random(1,35) --- 35 is just an example of max. amount of rows in table 2
    --etc up to RandTable = 6
    Change Scene ShowJoke -- or whatever your scene is called with the Display Text on it


    Now in your actor showing the Display Text behaviour, amend to:

    When RandTable = 1
    Display Text tableCellValue(yourTable1,Randrow,1)
    Otherwise
    When RandTable = 2
    Display Text tableCellValue(yourTable2,Randrow,1)
    Otherwise
    When RandTable = 3
    Display Text tableCellValue(yourTable3,Randrow,1)
    Otherwise
    ---etc up to When RandTable = 6

    Edit: Bray beat me to it!

    Hi Gyro

    Thanks my man..that is superb...if it get t working i'll let you know :)

    Thanks again...

    Braydon...close mate, close! :)

    It takes a Zombie to know a Zombie!!!

Sign In or Register to comment.