How to pick random from a table without getting duplicates

Epsilon94Epsilon94 LondonMember, PRO Posts: 8
I've made a table containing 50 different words. I have 6 different text fields that fetches a random word from the table.
Here's what I can't figure out:

1. How to pick a random word from the table without getting duplicates within the other 5 fields.
2. How to make it pick every word except for a specified one, make it pick from the 49 not specified.

Thanks in advance.

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Copy that table to a temp table and after you select a row, save that word then delete the row. random(1,tableRowCount(temptable))
  • Epsilon94Epsilon94 LondonMember, PRO Posts: 8
    Thanks for helping out.

    I don't quite get your idea, could you please elaborate?
  • jorkosjorkos Member, PRO Posts: 353
    use excel to produce a table - 6 columns with a number between 1 and 50 for each column - make it a thousand rows - pick the row randomly and draw from that
  • ramza04ramza04 Presque Isle, MaineMember, PRO Posts: 25
    I'm making a word game right now that when it starts I have the game copy my words table. Then I randomly select a word and delete that row for that word. This way it gives me a different word the next time it looks through the table. Once all the words are used I copy the wordcopy table back to the original table.
  • ramza04ramza04 Presque Isle, MaineMember, PRO Posts: 25
    edited March 2014
    Also for ur second question. You could probably make a rule saying IF wordID = (whichever word u don't want) then rerun the loop for looking up a word until u get the one u want
  • Epsilon94Epsilon94 LondonMember, PRO Posts: 8
    Ok, I'm starting to get it now. Thanks to everyone!

    I solved my first question with the copy table behaviour then delete the one that is being displayed. I do however still have some problems / questions :

    How can I make it so that one specific word gets displayed randomly in a different actor every time the level starts?

    Ex:

    I have 6 actors fetching data from the table, each time this specific level gets reset (try again) I need a predetermined word to appear on a new actor.

    This way you can't just reset the scene and get the highscore by spamming the same button now that you know where the answer is.

    Thanks.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    In one actor, at the top of its rule list (when the scene begins), have Change attribute game.wordPosition to random(1,6). Also add an integer attribute to each display actor and manually set it to a value between 1 and 6 depending on its position in the scene.

    In each word display actor, have When attribute self.myPosition=game.wordPosition --> Display Text or Change Image or however you want to display the word.

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

  • Epsilon94Epsilon94 LondonMember, PRO Posts: 8

    Thanks @tatiang‌

    I'm still having problems with "duplicates". It looks like the row that gets picked won't be deleted properly. My table does not have to be saved between different sessions, do I still have to use the copy table behaviour?

Sign In or Register to comment.