Working with tables

Hello all, great resource here and it has helped immensely while i have been building my quiz app.

My question is this, if i have a master list say with 100 questions and answers and i would like to randomly copy ten rows into a new table so each time the user plays they get 10 that with the random shuffle should mean not much repeats unless they play the same level over and over?

Comments

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

    Here's the algorithm I would use:

    1. Make a master table with your 100 questions and answers
    2. Create a table with 10 rows each with a value from 1 to 10
    3. Choose a random number from 1 to 91 to serve as the starting row number
    4. Choose a random number from 1 to tableRowCount(OneToTenTable)
    5. Add Table Row to pullTable if first row is not empty
    6. Change Table Value of last row of pullTable, column 1 to tableCellValue(masterTable,startingRowNumber+randomNumber,1)
    7. Change TableValue of last row of pullTable, column 2 to
    8. tableCellValue(masterTable,startingRowNumber+randomNumber,2)
    9. Delete row at randomNumber position from OneToTenTable
    10. Repeat steps 4-8 until OneToTenTable has no rows left

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

  • egyptcapriegyptcapri Member Posts: 17
    edited January 2015

    not sure i understand step 5

    think i get most of this actually trying to incorporate it at the moment.

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

    Step 5 is the least intuitive but the reason for it is that if you add a row to an empty table then you end up with a table that looks like this:

    [blank]
    question1 answer1
    question2 answer2
    ...

    So instead if the first row is empty, just change the value of the cells (step 6). Once you've added data to the first row, you'll always thereafter want to add a row first so that there's somewhere to add new data.

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

  • egyptcapriegyptcapri Member Posts: 17

    ok cool for that explanation.

    working on my code so will let you know how it works out.

  • egyptcapriegyptcapri Member Posts: 17

    ok sorry but after starting to work on this i totally blanked and now am lost as to how to implement this.

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

    Sorry to hear that! Is there a question you have about a particular step?

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

  • egyptcapriegyptcapri Member Posts: 17

    how do i go about doing step 5 im sorry ive been looking at your post and as im learning the software and also programming im drawing a blank. Thanks again

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

    Add Table Row to pullTable if first row is not empty

    When text expression tableCellValue(tableName,1,1) is not [blank]
    Add row to end of table
    Change Table Value [row: tableRowCount(tableName)]

    The first time through, it will just change the value of the first row but thereafter, it will add a row and then change the value within that row.

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

Sign In or Register to comment.