Reset scene with random word picker - make sure it doesn't pick the same word???

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

Best Answers

  • KevinCrossKevinCross London, UKPosts: 1,894
    edited July 2013 Accepted Answer
    I 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.
  • KevinCrossKevinCross London, UKPosts: 1,894
    edited July 2013 Accepted Answer
    It'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

  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    Yes I am.

    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.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Can you not add a 2nd column to your 10 row 1 column table which you set with a flag when the word has been used before?
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    when you say 'set with a flag', do you mean like making it a true or false attribute? Like a boolean?

    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? :)
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited July 2013
    I've not really looked at tables yet as I only started to look at GameSalad again a week or so ago, but yes that's what I mean, a true or false/boolean attribute.

    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
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    Thanks for explaining that. I understand what you're trying to do but I'm having an issue trying to implement it.

    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 ;)
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Because the rules are programmed in a way that won't let you say if table cell = expression you'll probably need to store the table cell in an attribute and then in your rule say if attribute = expression. This would be the amended example (see lines 3 and 4):

    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.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited July 2013
    Thinking about it, the above approach will slow down your game if you've got a table with loads of words, and only a few free to use. Perhaps you should look at copying the table, and with the copy delete words/rows that have been used. You can then continue your current approach:

    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.
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    Thanks @the12thplaya

    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.
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    Actually.....maybe I could say if the Scene's 'Level' attribute is 1, use the original table and if the 'Level' attribute is 2, then use the copied table. Right?

    Hmm..anyways, I'll have a play around now and see what I get...

    Thanks again!
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    When you tried it before, did you save the table? That's supposedly saves it locally. You would hope that it wouldn't reset when you switch scenes, otherwise I'm not really sure what the point of saving it would be.

    Good luck and you're welcome.
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    Hi again. So I've now tried using your suggestion of saving the table and sadly its still not working - the game repeats words. :(

    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
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I don't have any suggestions now but am happy to see if I can create something quick and simple in GameSalad later on tonight (in about 9 or 10 hours) to do what you want. I can't do much on my project until the Apple Developer site is up and running again so it's not a problem

    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.
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    Hi Kevin. Unfortunately no, I don't use a new scene for each level. I reset the scene when I want to go to the next level, or next word.

    I really appreciate you looking into this though - thanks!
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    Hi Kevin,

    Thank you so much! This is great :D

    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!
  • KevinCrossKevinCross London, UKMember Posts: 1,894



    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'
    1. That sounds correct.

    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
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    Wicked, thanks.

    I'll get it now! Wish me luck!
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    Hi Kevin.

    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!
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    sorry, I didn't mean 'correct layers' in my second paragraph. I meant 'correct letters'
  • 1LuVP4nc4k3S1LuVP4nc4k3S Member Posts: 62
    I worked it out! You were right by the way. It was because the copy table was just there on its own as a rule so every time you were in a level it would overwrite the copy table with the original words. I've now placed that copy rule inside another stating 'if game.LEVEL is 1' then copy then. If not, then it will just use the copy table.

    IT. NOW. WORKS!! Oh my god, I am relieved!!!

    Thank you @KevinCross!!! It works beautifully now :D
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    You're welcome. I'm glad you got it sorted in the end :)
Sign In or Register to comment.