12 Replies Latest reply on Jul 26, 2010 7:54 AM by efeelo

    Counting letters in a word

    efeelo

      I am using lingo to count and display letters in a word but my script is stuck on a point. Can any help to solve this?

       

      property

       

       

      SpriteNum

      global

       

       

      gCurrentCounter, CurrentWord, lettersofCurrentWord, sSoundName

      On

       

       

      MouseDown me

       

      if

       

      gCurrentCounter < 10 then

      p =

      "00" & gCurrentCounter

      else if

       

      gCurrentCounter < 100 then

      p =

      "0" & gCurrentCounter

      else

      p = gCurrentCounter

      end if

      j =

      1

      letter_no =

      spritenum

      letter_name =

      member("PE_" & string(j)).text

      letter_uppercase =

      "A"

       

       

       

      -- puppetSound 1, "A sound"

       

       

      CurrentWord =

      member("word - " & p)

      i =

      1

      If

       

      sprite (letter_no).within(sprite(spritenum)) Then

      if

       

      charToNum(member(CurrentWord).paragraph[1].char[1]) <= 90 then

      member

       

      ("pe_space_" & string(i)).text = letter_uppercase

      else

      member

       

      ("pe_space_" & string(i)).text = letter_name

      end if

       

       

      end if

       

      set the

       

      loc of sprite letter_no to point(300,330)

       

      -- i = 2

      put

       

      i

       

      -- repeat while i <= CurrentWord.char.count

       

      if

       

      charToNum(member(CurrentWord).paragraph[1].char[i]) >= 200 then

      member

       

      ("pe_space_" & string(i)).text = member(CurrentWord).paragraph[1].char[i]

      sprite

       

      (letter_no).within(sprite (10 + i))

      else

      member

       

      ("pe_space_" & string(i)).text = letter_name

       

      end if

       

      i = i +

      1

       

       

      -- end repeat

       

       

       

       

      end

       

      mousedown me

        

      end

        • 1. Re: Counting letters in a word
          Sean_Wilson Adobe Community Professional

          The code you posted is illegible. Please format it and indicate where your problem is.

          • 3. Re: Counting letters in a word
            efeelo Level 1

            I can use grab and move the letter one by one to the respective positions of

            a letter within the word to make my word, but by using on mousedown with a

            click on the letter or onkeydown is my issue here. I need to make this work

            that each letter in a word will go to its position one by one on a click or

            on pushing on the key on my keyboard to move to its position in the word

            within the space provided for it. Just as if you are spelling a word.

            • 5. Re: Counting letters in a word
              efeelo Level 1

              Hello Sean_Wilson

               

              I have tried twice to upload the whole code to you but it kept been

              truncated at that same point, I hope my explanation of what I am trying to

              do here is clear to you. Any suggestions will be helpful. Thanks.

              • 6. Re: Counting letters in a word
                Sean_Wilson Adobe Community Professional

                I don't know why your code posting keeps getting truncated. Try copying it from the script editor and pasting it into the top pane of your Message Window, then copy and paste from there into the forum. Then select it all and place it in a code box, so that formatting is retained - use the >> symbol above and choose Syntax Highlighting -> Plain

                 

                Sorry, I still don't understand what your code is trying to do.

                • 7. Re: Counting letters in a word
                  efeelo Level 1

                  property SpriteNum

                   

                  global gCurrentCounter, CurrentWord, lettersofCurrentWord, sSoundName

                   

                  On MouseDown me

                   

                   

                        if gCurrentCounter < 10 then

                   

                          p = "00" & gCurrentCounter

                   

                          else if gCurrentCounter < 100 then

                   

                          p = "0" & gCurrentCounter

                   

                          else

                   

                          p = gCurrentCounter

                   

                        end if

                   

                              j = 1

                   

                              letter_no = spritenum

                   

                              letter_name = member("PE_" & string(j)).text

                   

                              letter_uppercase = "A"

                   

                   

                   

                          -- puppetSound 1, "A sound"

                   

                   

                   

                              CurrentWord = member("word - " & p)

                   

                                  i = 1

                   

                                  If sprite (letter_no).within(sprite(spritenum)) Then

                   

                                      if charToNum(member(CurrentWord).paragraph[1].char[1]) <= 90 then

                   

                                          member("pe_space_" & string(i)).text = letter_uppercase

                   

                                              else

                   

                                          member("pe_space_" & string(i)).text = letter_name

                   

                                      end if

                   

                                  end if

                   

                   

                                  set the loc of sprite letter_no to point(300,330)

                   

                                  -- i = 2

                   

                                  put i

                   

                  repeat while i <= CurrentWord.char.count

                   

                   

                     if charToNum(member(CurrentWord).paragraph[1].char[i]) >= 200 then

                   

                       member("pe_space_" & string(i)).text = member(CurrentWord).paragraph[1].char[i]

                   

                                  sprite (letter_no).within(sprite (10 + i))

                   

                              else

                   

                                  member("pe_space_" & string(i)).text = letter_name

                   

                      end if

                   

                              i = i + 1

                   

                  end repeat

                   

                   

                  end mousedown me

                  • 8. Re: Counting letters in a word
                    Sean_Wilson Adobe Community Professional

                    Please explain again what your code is trying to achieve.


                    • 9. Re: Counting letters in a word
                      Mike Blaustein Level 4

                      As Sean mentioned, it would be very helpful to know what you are trying to do, and what this code is doing or not doing correctly.  But based solely upon the title of the thread, I am working under the assumption that you need to know how to count letters in a word.  Nothing in that block of code appears to be doing that or attempting to do that, so it is confusing... is the problem that it doesn't count the letters?  Or is that code unrelated to letter counting, in which case, I would question why you posted it...

                       

                      Anyway, you can get the number of characters in any given word of text like this:

                       

                      put "Mike".char.count

                      -- 4

                       

                      someText="my name is Mike"

                      put someText.word[1].char.count

                      -- 2

                       

                      So, just take whatever text you are looking for as a string, and use ".char.count" on it.

                      • 10. Re: Counting letters in a word
                        efeelo Level 1

                        Hello Sean_Wilson

                         

                        I am trying to put a "word" together by placing one letter at a time in a

                        space "sprite"  to make up this word "series of  sprites" by using mouse

                        click on each letters of the Alphabet on my stage or by using the keys on my

                        keyboard. Using grab and move works successfully but I prefer to use the on

                        MouseDown and/or on KeyDown to move the letters to their respective

                        positions to form my word on my stage.

                        Can you still help?

                        • 11. Re: Counting letters in a word
                          Sean_Wilson Adobe Community Professional

                          So what sort of sprite/member holds the completed word?

                           

                          Presumably the code you posted is attached to individual letters of the alphabet?

                           

                          I have re-posted your code with questions and comments interspersed - perhaps you could addess some of these:

                          global gCurrentCounter, CurrentWord, lettersofCurrentWord, sSoundName
                          property SpriteNum
                          
                          on mouseDown me
                            if gCurrentCounter < 10 then
                              p = "00" & gCurrentCounter
                            else if gCurrentCounter < 100 then
                              p = "0" & gCurrentCounter
                            else
                              p = gCurrentCounter
                            end if
                            
                            j = 1
                            letter_no = spritenum
                            -- I don't understand: since you declared j = 1
                            -- your local var 'letter_name' will always be member("PE_1").text
                            letter_name = member("PE_" & string(j)).text
                            -- again, you have hard-coded something with no apparent reason
                            letter_uppercase = "A"
                            
                            -- puppetSound 1, "A sound"
                            
                            CurrentWord = member("word - " & p)
                            
                            i = 1
                            
                            if sprite (letter_no).within(sprite(spritenum)) then
                              if charToNum(member(CurrentWord).paragraph[1].char[1]) <= 90 then
                                member("pe_space_" & string(i)).text = letter_uppercase
                              else
                                member("pe_space_" & string(i)).text = letter_name
                              end if
                            end if
                            
                            sprite(letter_no).loc = point(300,330)
                            
                            -- i = 2
                            -- i will always equal 1 because that's how you declared it above, and it isn't changed
                            put i
                            
                            -- can you explain what this block of code is doing?
                            -- I have no idea what the various members
                            -- member("pe_space_" & string(i))
                            -- are or how they're used
                            repeat while i <= CurrentWord.char.count
                              if charToNum(member(CurrentWord).paragraph[1].char[i]) >= 200 then
                                member("pe_space_" & string(i)).text = member(CurrentWord).paragraph[1].char[i]
                                -- 'within' is an operator that returns TRUE/FALSE
                                -- so it isn't clear what you're trying to do here
                                sprite(letter_no).within(sprite (10 + i))
                              else
                                member("pe_space_" & string(i)).text = letter_name
                              end if
                              i = i + 1
                            end repeat
                          end mouseDown
                          
                          • 12. Re: Counting letters in a word
                            efeelo Level 1

                            **** Hello Sean see responses to questions in RED

                             

                            So what sort of sprite/member holds the completed word?

                                • Sean -  A complete set of sprite equal the number of letters in

                                • the word named pe_space_

                             

                            Presumably the code you posted is attached to individual letters of the

                            alphabet?

                                • Sean - You assumed right

                             

                            I have re-posted your code with questions and comments interspersed -

                            perhaps you could addess some of these:

                            global gCurrentCounter, CurrentWord, lettersofCurrentWord, sSoundName

                            property SpriteNum

                             

                            on mouseDown me

                            if gCurrentCounter < 10 then

                            p = "00" & gCurrentCounter

                            else if gCurrentCounter < 100 then

                            p = "0" & gCurrentCounter

                            else

                            p = gCurrentCounter

                            end if

                             

                            j = 1

                            letter_no = spritenum

                            -- I don't understand: since you declared j = 1

                            -- your local var 'letter_name' will always be member("PE_1").text

                            letter_name = member("PE_" & string(j)).text

                            -- again, you have hard-coded something with no apparent reason

                            letter_uppercase = "A" ***  Sean - In case the first letter is uppercase

                             

                            -- puppetSound 1, "A sound"

                             

                            CurrentWord = member("word - " & p)

                             

                            i = 1

                             

                            if sprite (letter_no).within(sprite(spritenum)) then

                            if charToNum(member(CurrentWord).paragraph[1].char[1]) <= 90 then

                            member("pe_space_" & string(i)).text = letter_uppercase

                            else

                            member("pe_space_" & string(i)).text = letter_name

                            end if

                            end if

                             

                            sprite(letter_no).loc = point(300,330)

                             

                            -- i = 2

                            -- i will always equal 1 because that's how you declared it above, and it

                            isn't changed

                             

                                • Yes Sean, this is the reason for my been stuck on the first sprite

                            or letter of my word. I was hoping to achive repeat effect by clicking on the mouse

                            or keydown to get word spelt.

                            But on mouseDown me or keyDown does not work with my code

                             

                            put i - This tell me that I am stuck on i = 1

                             

                            -- can you explain what this block of code is doing?

                            -- I have no idea what the various members

                            -- member("pe_space_" & string(i))

                            -- are or how they're used

                             

                                • Sean the pe_space_  are the fields where my letter PE_ get attached to,

                            so when I release my letters on grab and move they are within these

                            sprites/fields

                            So, Sean can still help?

                             

                            repeat while i <= CurrentWord.char.count

                            if charToNum(member(CurrentWord).paragraph[1].char[i]) >= 200 then

                            member("pe_space_" & string(i)).text =

                            member(CurrentWord).paragraph[1].char[i]

                            -- 'within' is an operator that returns TRUE/FALSE

                            -- so it isn't clear what you're trying to do here

                            sprite(letter_no).within(sprite (10 + i))

                            else

                            member("pe_space_" & string(i)).text = letter_name

                            end if

                            i = i + 1

                            end repeat

                            end mouseDown

                             

                            Message was edited by: efeelo