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!
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
-
SnapFire Posts: 361
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 -
tatiang Posts: 11,949
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
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.