Scrambling a word

I am making a word scrambling game and was wondering how you would take the letters that are in a table and rearranging them?
I have each letter in a column which are in the same row. How could I scramble the column order in the table to get a differently scrambled word and display the text every time?
Thank You!

★ My Apps | Gamesalad Tutorials : Youtube Channel , Website. ★

Comments

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    edited April 2013
    Why not just rearrange the actors which grab a value from your table?

    For example:

    Actor 1: h
    Actor 2: e
    Actor 3: l
    Actor 4: l
    Actor 5: o

    Then, create a "scramble" table - and you can create as many rows are you'd like, but I've listed 5 below.


    They could look something like this:
    24153
    53214
    15324
    31245
    45132

    And so on...

    Then, after you've assigned a letter to the actor, just pick a random row from your "scramble" table and assign the actors their position based off of the value in the columns.

    So if it chose row 1:

    Actor 1 would go to spot 2
    Actor 2 would go to spot 4
    Actor 3 would go to spot 1
    Actor 4 would go to spot 5
    Actor 5 would go to spot 3

    Hope this helps,
    Braydon
  • blue_elephantblue_elephant Member Posts: 505
    I don't know. There will be around 200+ words since the goal of the game is to unscramble the words. That seems like it would make it inefficient and have way to many actors. Maybe I'm wrong? I don't know. Is there another way?

    ★ My Apps | Gamesalad Tutorials : Youtube Channel , Website. ★

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    I don't think it is an inefficient way to do it. Your letters will still be scrambled.

    Even if the person gets the same word twice, the game will most likely choose a different row, which means a different scramble order.
  • DenimSharkDenimShark Member Posts: 192
    Reuse the actors for each word, assuming you dont have the 200 words all displayed at once on the scene
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    How many letters are you going to have on-screen?
  • DenimSharkDenimShark Member Posts: 192
    Also search "fisher yates" shuffle on the forums for more info on scrambling
  • blue_elephantblue_elephant Member Posts: 505
    The words will be up to 11

    ★ My Apps | Gamesalad Tutorials : Youtube Channel , Website. ★

  • blue_elephantblue_elephant Member Posts: 505
    I will try the actors

    ★ My Apps | Gamesalad Tutorials : Youtube Channel , Website. ★

  • DanDaMan123DanDaMan123 Member Posts: 216
    the best way to scramble words:

    (using string variables 'word' + 'newWord')

    1. you have a word in a text variable
    2. make a random number
    3. take the corresponding letter to that number from the word
    4. add that letter to a new text variable
    5. delete that letter from the original word
    6. repeat from 2

    this can be done easily in code but you might have to be creative in gamesalad to make up for lacking functions and you will probably have to store the word in a temporary table.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013

    Hi @blue_elephant

    Similar in principle to @DanDaMan123 method but using Tables, and similar to @Braydon_SFX method in as much as there's a fair bit of work involved, here's my suggestion for a differently scrambled word and display the text every time via Tables, as you want:

    Attributes used: booleans: Start
    Integers: RandT, RandC, RandRow, GoNum, RowMax Text: ScrambledW, ActualWord

    9 Tables: name them T3Words, T4Words, T5Words, etc., up to T11Words. Each with the appropriate number of rows corresponding to the number of characters of the words in its Table + 1. (For instance, if it's the 11-word table, make 12 rows. This extra row will be explained later. The amount of columns will be the amount of words in each table (all columns set as Text, of course).

    So in the first row, put the actual complete word, one for each column. Then put each letter of a word in the column underneath, one letter per row. Then for all the other columns.

    • The following Rules are only half-tested but hopefully will work out for you: •

    --Presuming you'll have a Start button to generate a mixed up word each time, in its Rules:

    Rule: When touch is pressed
    Change Attribute Start to true


    --Now in the actor to display the mixed-up letters:

    Display Text scene. ScrambledW

    Rule: When Start is true
    Change Attribute RandT to random(1,9)
    --- 9 is an example of the amount of Tables you are using

    Rule: When RandT = 1
    Change Attribute RandC to random(1,30)
    --- 30 is an example of the amount of columns, i.e amount of words you are using in the first table
    Change Attribute GoNum to 1
    Change Attribute RowMax to 4

    Rule: When RandT = 2
    Change Attribute RandC to random(1,44)
    --- 44 is an example of the amount of columns, i.e amount of words you are using in the second table
    Change Attribute GoNum to 2
    Change Attribute RowMax to 5
    --etc, up to RandT=9

    Rule: When GoNum is 1
    Change Attribute RandRow to random(2,RowMax)
    --- starting at 2nd row, to number of letters in the words in this table + 1
    Change Attribute ScrambledW to ScrambledW..tableCellValue(T3Words,RandRow,RandC)
    Add/Remove Row Table: T3Words
    Action: Remove Row at Index RandRow
    Change Attribute RowMax to RowMax-1
    Change GoNum to GoNum*10

    Rule: When GoNum is 2
    Change Attribute RandRow to random(2,RowMax)
    --- starting at 2nd row, to number of letters in the words in this table + 1
    Change Attribute ScrambledW to ScrambledW..tableCellValue(T3Words,RandRow,RandC)
    Add/Remove Row Table: T4Words
    Action: Remove Row at Index RandRow
    Change Attribute RowMax to RowMax-1
    Change GoNum to GoNum*10
    --etc, up to GoNum = 9

    Rule:
    When GoNum > 9 and RowMax > 1
    Change Attribute GoNum to GoNum/10
    Otherwise
    Change Attribute Start to false

    ----------

    Note : when comparing then actual word with user input, use this in the Display Text in the actor showing the word:

    Rule: When GoNum = 1
    Change Attribute ActualWord to tableCellValue(T3Words,1,RandC)
    Display Text ActualWord
    Rule: When GoNum = 2
    Change Attribute ActualWord to tableCellValue(T4Words,1,RandC)
    Display Text ActualWord
    Rule: When GoNum = 3
    Change Attribute ActualWord to tableCellValue(T5Words,1,RandC)
    Display Text ActualWord
    etc.


    ------------

    OK, that's definitely in the right ballpark but is bound to need some refining. For instance, after the table to use has been randomly selected, it perhaps needs to be copied so that the copy of the tables has the rows removed, not the original, etc.

    But I'm certain there's enough here to give you a head start at least.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013

    *bump* in case @blue_elephant missed my suggestions and they could help out as well...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • blue_elephantblue_elephant Member Posts: 505
    Thanks

    ★ My Apps | Gamesalad Tutorials : Youtube Channel , Website. ★

  • blue_elephantblue_elephant Member Posts: 505
    @gyroscope
    I did what you said but absolutely nothing happens. Am I missing something?

    ★ My Apps | Gamesalad Tutorials : Youtube Channel , Website. ★

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013
    @gyroscope
    I did what you said but absolutely nothing happens. Am I missing something?
    Yes! ;-) Or I've missed something and the programming I suggested needs correcting...

    I'd need to see the gamefile to check it out for you. Any chance of you attaching the file?

    Edit: possibly the loop "mechanism" isn't working.... (in this case, the GoNum loop). For some reason, I've been having trouble lately with loops in GSC....

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013

    Hi @blue_elephant Thanks for sending me your file via DM; I took a look at the gamefile and yes, as I said there, fill out all of the Tables with at least a few words each so you've something to test with; and consider using two actors as fields to take two Display Text behaviours to show text, (before you still might decide to replace these with individual letters/actors after).

    So get to that point and resend, and I'll take another look if you like, hopefully you'll be nearer getting the Rules to work.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • blue_elephantblue_elephant Member Posts: 505
    Ok, ill work on it

    ★ My Apps | Gamesalad Tutorials : Youtube Channel , Website. ★

Sign In or Register to comment.