Reset scene with random word picker - make sure it doesn't pick the same word???
1LuVP4nc4k3S
Member Posts: 62
I'm new to GameSalad and in fact coding as well! I've been building a hangman-type game and I feel I've gotten stuck at about 75% of the way there. The game can pick a word at random (using my 'Word Picker' actor) and using the custom keyboard I made, the user can see if the words they click are in the guessed word. If they are, that letter appears up above in the word, if not the 'Guesses Left' counter shows 1 less.
The bit I'm stuck on now is that once the user guesses the correct word, a message appears saying 'You win!' and a 'Next word' button shows up. I want to make it so that it goes back to the beginning of the scene (so reset scene?) but this time making sure it doesn't pick the same word. I've tried copying the table the Word Picker uses to another blank one for the reset scene (based on the Level attribute) but it then stops picking words and therefore goes blank.
*The reason I want to use reset is because when the user presses a letter I destroy the actor. If its the correct letter it spawns another one to show in the correct place. Basically so that whether you get a success or fail message, the entire keyboard gets wiped out. So if I didn't use reset, I wouldn't be able to delete the spawned actors spelling out the guessed word (along with the lines that sit underneath it (they get spawned at the beginning depending on what word is picked).
So bottom line - the question is: how do I remember what word was guessed in Level1 so that once you get to Level 2 (reset scene) it doesn't pick that name. In addition to that - how do I then add to that memory of what word was guessed in Level 2?
I'm sorry if any of that was confusing!
Many thanks,
1LuVP4nc4k3S
The bit I'm stuck on now is that once the user guesses the correct word, a message appears saying 'You win!' and a 'Next word' button shows up. I want to make it so that it goes back to the beginning of the scene (so reset scene?) but this time making sure it doesn't pick the same word. I've tried copying the table the Word Picker uses to another blank one for the reset scene (based on the Level attribute) but it then stops picking words and therefore goes blank.
*The reason I want to use reset is because when the user presses a letter I destroy the actor. If its the correct letter it spawns another one to show in the correct place. Basically so that whether you get a success or fail message, the entire keyboard gets wiped out. So if I didn't use reset, I wouldn't be able to delete the spawned actors spelling out the guessed word (along with the lines that sit underneath it (they get spawned at the beginning depending on what word is picked).
So bottom line - the question is: how do I remember what word was guessed in Level1 so that once you get to Level 2 (reset scene) it doesn't pick that name. In addition to that - how do I then add to that memory of what word was guessed in Level 2?
I'm sorry if any of that was confusing!
Many thanks,
1LuVP4nc4k3S
Best Answers
-
KevinCross London, UKPosts: 1,894I believe the attach project does what you need. I've ran it several times and the words do not duplicate between levels 1 and 10. It uses Reset Scene like you mentioned in your last post.
It also only uses two tables, the original, and a copy which the words are deleted from. When it gets back to level 1 the table is copied/reset to include all 10 words. The behaviours needed are on the "Show Word Button" actor.
Apologies for the lack of visual design!
EDIT: After posting I realised that I could have replaced the hardcoding of 10 with table row counts, that way you could add more words to the table at a later date without having to change the number 10 manually in your behaviours. -
KevinCross London, UKPosts: 1,894It's hard to really understand what's happening without seeing it but if you're finding the block of code is repeating continuously, unlike mine which only activated when being pressed maybe try putting a rule around your behaviours to check if the game has started. If it's started then you don't want to re-copy the table which I'm guessing is what's happening to yours for it to not remember what words have been used each level. Does that make sense? Do you think that will solve the problem?
Is it a case that your code is running continuously and in doing so it's overwriting the tables on each level/scene reset?
Flag the game as started until all of the words have been found or they trigger an action that starts the game again. When all words have been found, or they trigger a restart the game has started flag will be set as false, and it's then you copy the table ready for a new game.
Answers
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
I have a 'WORD_PICKER' actor in the scene that sets its own attribute 'Word picker' to a random value chosen from my table. My table has 10 rows and 1 column. In each row I have an integer listed from 1-10. These represent the words I have available to pick.
So if the word picker selects 5 it has selected the word 'apple' etc.
If so, how would I then apply that logic to the game? This is what I have right now:
set self.Word picker to tableCellValue(game.TB_WORD_PICKER_NUMBER,random(1,tableRowCount(game.TB_WORD_PICKER_NUMBER)),1)
Then I have a bunch of other rules that say things like:
if self.Word picker = 1
then make 'apple' true
Does that make sense?
Are you not able to set up a loop that randomly picks a number every 0 seconds, and inside that loop have a rule that checks if the tableCellValue(table, random row, column 2) equals false. If so jump out of the loop and use the word picked.
If it's not possible to jump out of the loop set a game attribute to true which a rule around or inside the loop will check and skip running if true (which means you've found a word to work with). When you need to pick a word again, set the game attribute to false and the loop should start up again. Something like PickingWord = False/True
I'm not in a position to try this but in principle it seems doable. I would probably look at adding the words to the table too, that way you're picking a random row, and from that row you can check the "if used" flag, as well as get the word picked which should cut down the number of "if self.Word picker = 1 then make 'apple' true" rules
Others may have smarter suggestions on how to do this but that's probably how I'd tackle it. Something a long the lines of:
Rule: If PickingWord = True
Loop: Every 0 Seconds
Rule: If Table Cell (Table, Random Row, Column 2) = False
Change Attribute: RandomWord = Table Cell (Table, Random Row, Column 1)
Change Attribute: PickingWord = False
End Rule
End Loop
End Rule
Sorry if this seems like such a simple silly question, but I am new to GameSalad, but how are you able to make an IF statement on a table cell?
I've tried adding a rule where I drag an attribute condition, so that I can say if tablecell row 1 column is false do so and so, but it doesn't let me. I suppose this must be a limitation in GameSalad, but is there some kind of work around?
Sorry if I've gotten this totally wrong!
Thanks for your continued patience
Rule: If PickingWord = True
Loop: Every 0 Seconds
Change Attribute: WordFlag = Table Cell (Table, Random Row, Column 2)
Rule: If WordFlag = False
Change Attribute: RandomWord = Table Cell (Table, Random Row, Column 1)
Change Attribute: PickingWord = False
End Rule
End Loop
End Rule
If you're still having trouble I can have a play around with it later this evening when I get in from work and will attach a working example if I have any luck.
tableCellValue(game.TB_WORD_PICKER_NUMBER,random(1,tableRowCount(game.TB_WORD_PICKER_NUMBER)),1)
Because you've copied the table you've still got the original one with all of the words in. There is a behaviour in the list to copy tables I believe. Copying the table is something that you'd want to do in the game and not in Game Creator manually.
I'd also still recommend adding the words to the table, especially if you want to add more to it at a later date, because then you won't have to have a rule set up for each word.
I have tried copying the table before, but because everytime you go to the next level and resetting the scene I don't think it worked properly. Also, if I copy the table then that means on the next level we should use that new table with the deleted row. But that can't be possible if you reset the scene, right? Because then the word pickers goes back to referring to first table.
Hmm..anyways, I'll have a play around now and see what I get...
Thanks again!
Good luck and you're welcome.
Here's what I did. I'm trying to see what went wrong:
1. Added a game attribute called LEVEL
2. Made 9 more blank tables. So far for the game I only have 10 words to be guessed, so here are the tables I've now got:
- Master table (10 rows 1 column - integers)
- Level 2 table (10 rows 1 column)
- Level 3 table (9 rows 1 column)
- Level 4 table (8 rows 1 column)
- Level 5 table (7 rows 1 column)
- Level 6 table (6 rows 1 column)
- Level 7 table (5 rows 1 column)
- Level 8 table (4 rows 1 column)
- Level 9 table (3 rows 1 column)
- Level 10 table (2 rows 1 column)
3. On the word actors I've put this rule:
If actor is visible and game.LEVEL is 1, then copy master table to level 2 table, remove row to index of scene.Word PICKER (this attribute is an integer like the tables it references), save level 2 table
I did that for all levels on each word actor
4. On the word picker actor I changed the rule a little from before. I made sure that I included that if game.LEVEL is 1 then randomly pick number from master table etc. etc.
If you have any ideas why this went wrong please feel free to share!
Thanks again
Just to confirm, is each of these levels a new scene? I'll probably set up something simple with two buttons on each scene if so, one button to pick and display a random word, and the other button to move to the next scene.
I really appreciate you looking into this though - thanks!
Thank you so much! This is great
Just so I understand completely, I'm looking at your ''Show Word Button' actor and some things appear to be missing (I don't know if its because I'm looking at a mac project on a Windows computer?):
1. In the 'Reset Words If Level 1' rule, would you be copying the master table to the copy table?
2. In the 'Set Chosen Word' rule, are you setting 'game.Chosen Word' using the table cell value from the Fruits_Copy table using the 'Chosen Word Index' attribute as reference to which row to use, and that its in column 1?
3. The last rule, 'Delete Word', doesn't have anything in it. It just says 'No editable tables exist in the project'. In this case, were you going to be using the add/remove row behaviour to remove the chosen word from the copied table? If so, just to check (sorry), would it read like this:
remove row at index 'game.Chosen Word Index'
Is that correct? Sorry for all the questions!! This is so cool you've got this working though! I'm dying to try it out myself!
Thanks!
2. Yep that's what I was doing.
3. Sorry some of these rules might not have opened correctly for you because I created it in a Beta version of GameSalad (and on a Mac). But yes, the Delete Word part should be removing the row from the table by index, and the index comes from game.Chosen Word Index.
I hope you can get it to work
I'll get it now! Wish me luck!
Ok, so I tried it and it failed but only because I tried applying it to the scenario I have, which I think is slightly different.
The way you have it, you have to click a button to show a randomly chosen word. In my game, I don't want the randomly chosen word to show, because the player has to guess it by pressing the correct layers, which then make that corresponding letter show.
So basically, my Word Picker actor is offstage and is never shown in 'display text'. So my problem was where to put your rules?
At first, I thought I'd put the reset scene, if game.LEVEL <10, and remove row rules to the 'Next Word' actor as these rules *I think* only need to happen when you're ready to go up a level. I then made sure the other rules (Copy master table, set Chosen Word Index, set Chosen Word) should go on the Word Picker actor as this should happen immediately once you enter the scene.
Unfortunately this didn't work though and its still repeating stuff!
Help!
IT. NOW. WORKS!! Oh my god, I am relieved!!!
Thank you @KevinCross!!! It works beautifully now