how to spawn random letters for word game?

For my word game, I want to have a grid of letters for a player to choose from in the middle of the screen. How do I set it up so that the initial grid of letters (around 16 letters) is set up randomly (from A-Z, letters can be repeated)?

Then, how do I set it up so that if a letter is chosen by a player (and thus, removed from the grid), it is then replaced by another random letter (again, from A-Z, and it can be a letter already on the grid, or already chosen)?

I've searched all over GameSalad, and while I've found similar discussions, I don't think I've found an answer to this. I'm sure the answer is elementary, but I'm new to all this. So if anyone can help, or point me to a good tutorial, I'd appreciate it.

Thanks!

Best Answers

  • SnapFireSnapFire Posts: 361
    Accepted Answer
    How about this, make a rule that generates a random number when needed, and then decode it with another rule that says 'if number is = to #, then set your variable to a letter. You'd have to have a rule for each letter though.. But I think it's probably the best way to do it. Make sure you are using the control+c / control+v shortcuts to copy and paste the rules. Then you just have to change one thing in each one

    Hope this helps,
    - Thomas
  • tatiangtatiang Posts: 11,949
    Accepted Answer
    How about this, make a rule that generates a random number when needed, and then decode it with another rule that says 'if number is = to #, then set your variable to a letter. You'd have to have a rule for each letter though..
    Better to use a table for this. Put each letter of the alphabet, A to Z, in a row.
    A
    B
    C
    D
    ...

    Then have a single behavior: Change Attribute self.Letter to tableCellValue(AlphabetTable,self.randomNumber,1). If you have images named A.png, B.png, etc., then you have one more behavior after that: Change Attribute self.Image to self.Letter.

Answers

  • whompywhompy Member Posts: 27
    Thanks, SnapFire- that's basically what I did after I finally found this tutorial video:

    Now I just have to figure out how to lay the letters out in a grid, and some of the other mechanics involved in word games.
  • whompywhompy Member Posts: 27
    Thanks, Tatiang!
  • ShmirlyWhirlShmirlyWhirl Member Posts: 189
    I second @tatiang 's method. Especially because if you want to make certain letters appear more frequently, all you need to do is add some extra rows to the table.
Sign In or Register to comment.