6 Replies Latest reply on Jun 16, 2008 5:55 AM by Newsgroup_User

    creating a text entry field with restrictions

    cat_in_the_bag
      Hey,

      I am currently having a problem with creating a Text Input that can work as a kind of pasword box. In the game that I am designing the user needs to type in the correctly spelling of a word. If the spelling is correct the user progresses to another page (marker), if incorrect the user progresses to a different page (marker). The user also needs to be able to see what they are typing, so I can’t use the default password behaviour. Any help would be greatly appreciated.

      Thanks
      Matt
        • 1. Re: creating a text entry field with restrictions
          Level 7
          I don't understand your requirements. You talk about a password entry
          field, but then state that you don't need masking. Why won't a regular
          #text or #field sprite do what you need?
          • 2. Re: creating a text entry field with restrictions
            cat_in_the_bag Level 1
            The user has to enter the correct spelling of a word in the text input field, if the spelling is correct they progress to the next question, if they are incorrect they return to the start. Is this at all possible?

            Thanks
            • 3. Re: creating a text entry field with restrictions
              Level 7
              When would the program check for the correct spelling? For example is
              there a button on the stage that is used to check? Or when the user
              presses Enter? Or something else? Clearly you can't check every time
              the user presses a key since it would immediately jump to the "wrong
              answer" frame on the 1st keypress, be it correct or not.
              • 4. Re: creating a text entry field with restrictions
                Level 7
                As Mike said, you have not fully defined how the program should behave.
                In particular, when should the program 'test' the word. Here is a
                behavior that you can attached to an editable text sprite that tests the
                word as the user is typing it. As long as they spell each letter of the
                correctly, they can continue. As soon as they type a wrong letter, the
                code jumps back to the beginning.

                The behavior defines 3 properties. When you apply the behavior to a
                sprite, Director will prompt you to enter these properties. You can
                always go back and change them in the property inspector if needed.

                1) spellWord - This is the word that the user must spell. It is not case
                sensitive.

                2) correctLabel - This is the frame label that you want the program to
                jump to if the user correctly spells the word. If you leave it empty,
                the program jumps to the next label on the score.

                3) incorrectLabel - This is the frame label that you want the program to
                jump to if the user does not correctly spells the word. If you leave it
                empty, the program jumps to first label on the score.

                Here is the script of the behavior. Watch out for unintended line
                wrapping that will probably occur in your newsreader or web forum. There
                should be 38 lines. If the line breaks occur you will have to remove
                them. I have a simple demo movie that I can email you, if you want it.
                If you do post your email address, be sure to obscure it some how,
                something like

                cat at bag {SPAM sux} dot com

                instead of

                cat@bag.com


                ----------------------------------------------------------------
                property spriteNum

                on beginSprite me
                sprite(spriteNum).member.text = ""
                end

                on endSprite me
                sprite(spriteNum).member.text = "unitialized"
                end

                on keyUp me
                if sprite(spriteNum).member.text = sprite(spriteNum).spellWord then
                if sprite(spriteNum).correctLabel = "" then
                go next
                else
                go sprite(spriteNum).correctLabel
                end if
                else
                if sprite(spriteNum).member.text <>
                sprite(spriteNum).spellWord.char[1..sprite(spriteNum).member.text.char.count]
                then
                if sprite(spriteNum).incorrectLabel = "" then
                go the labelList.line[1]
                else
                go sprite(spriteNum).incorrectLabel
                end if
                else
                -- do nothing, they have spelled the word correctly so far
                end if
                end if
                end


                on getPropertyDescriptionList me
                description = [:]
                addProp description,#spellWord, [#default:"defaultWord",
                #format:#string, #comment:"Word to spell correctly"]
                addProp description,#correctLabel, [#default:"", #format:#string,
                #comment:"Where to go if word is correctly spelled"]
                addProp description,#incorrectLabel, [#default:"", #format:#string,
                #comment:"Where to go if word is not correctly spelled"]
                return description
                end
                ----------------------------------------------------------------
                • 5. Re: creating a text entry field with restrictions
                  cat_in_the_bag Level 1
                  Thanks the video could be useful. My address is cat_in_the_bagAtHotmailDotCom.

                  Originally I thought I would make the command work so that when the user has finished typing the word into the Input Text field, they press Enter key and then move to the relevant page (depending on weather they spelt the word correctly or not).
                  • 6. Re: creating a text entry field with restrictions
                    Level 7
                    OK, a slight modification to the behavior then.

                    ----------------------------------------------
                    property spriteNum

                    on beginSprite me
                    sprite(spriteNum).member.text = ""
                    end

                    on endSprite me
                    sprite(spriteNum).member.text = "unitialized"
                    end

                    on keyDown me
                    if the KeyCode = 36 then
                    if sprite(spriteNum).member.text = sprite(spriteNum).spellWord then
                    if sprite(spriteNum).correctLabel = "" then
                    go next
                    else
                    go sprite(spriteNum).correctLabel
                    end if
                    else
                    if sprite(spriteNum).incorrectLabel = "" then
                    go the labelList.line[1]
                    else
                    go sprite(spriteNum).incorrectLabel
                    end iF
                    end if
                    else
                    pass
                    end if
                    end

                    on getPropertyDescriptionList me
                    description = [:]
                    addProp description,#spellWord, [#default:"defaultWord",
                    #format:#string, #comment:"Word to spell correctly"]
                    addProp description,#correctLabel, [#default:"", #format:#string,
                    #comment:"Where to go if word is correctly spelled"]
                    addProp description,#incorrectLabel, [#default:"", #format:#string,
                    #comment:"Where to go if word is not correctly spelled"]
                    return description
                    end
                    -------------------------------------------------



                    cat_in_the_bag wrote:
                    > Thanks the video could be useful. My address is cat_in_the_bagAtHotmailDotCom.
                    >
                    > Originally I thought I would make the command work so that when the user has
                    > finished typing the word into the Input Text field, they press Enter key and
                    > then move to the relevant page (depending on weather they spelt the word
                    > correctly or not).
                    >
                    >