Page 1 of 1

Recognizing character "-"

Posted: Sun Feb 28, 2021 2:49 am
by oldummy
I'm playing with a morse code stack just to renew some coding skills,few as they may be.
I have an entry field where I put in some text, in this case "test".
I have another button that(using cps) that translates the letters to "-" or "." and puts it into fld "bla". This works ok.
I have audioclips for dit and dah imported into the stack.

I have a button that should play these dits or dahs audioclips as they are needed, but I seem to be having some trouble with playing them. I am wondering if the character "-" has some sort of strange reaction in LC.

Here is the script of the button that is supposed to do this:
on mouseUp
put fld "bla" into thebox -- the fld with the text "test" in this case
repeat for each char thechar in thebox
if thechar is "-" then put 1 after x--play ac "dah.wav" --I switched playing the ac to putting a digit instead

wait 4 ticks
if thechar is "." then put 2 after x--play ac "dit.wav"--I switched playing the ac to putting a digit instead

wait 4 ticks
end repeat
put x -- I keep getting 2222 rather than 1 2 2 2 2 1
end mouseUp

--These are the dits and dahs in fld "bla" _ . ... _
--Is this something with the "-" character?

Re: Recognizing character "-"

Posted: Sun Feb 28, 2021 8:08 am
by bogs
oldummy wrote:
Sun Feb 28, 2021 2:49 am
--Is this something with the "-" character?
No, but you might try putting the hyphen in instead of the underscore ;)

This " _ . ... _" does not == " - . ... -"

Or, I suppose you could change your code to check for the underscore :D

Re: Recognizing character "-"

Posted: Sun Feb 28, 2021 12:30 pm
by AxWald
Hi,

just checked out of curiosity. This works:

Code: Select all

on mouseUp
   get fld "input_fld"                                                         --  where there's my input
   
   repeat for each char C in it
      if C = "-" then
         put 1 after myVar                                                          --  add a value for -
      else if C = "." then
         put 2 after myVar                                                          --  add a value for .
      else
         put "?" after myVar                             --  in case we have something unwanted there ...
      end if
   end repeat
   put myVar                                                            --  send result to msg for review
   
   repeat for each char C in myVar
      if C = "?" then next repeat                                                          --  skip those
      if C = "1" then
         play ac "1.wav"                                                   --  play imported audio clip 1
      else if C = "2" then
         play ac "2.wav"                                                   --  play imported audio clip 2
      end if
      wait 500 millisecs with messages                                   --  some room between sounds ...
   end repeat
end mouseUp
"Imported as control" are 2 short audio clips. They play a fine morsing.

I did it in 2 loops, so I can show a visual representation what's to be played after. And I check for unwanted input - always possible that spaces, CRs or such sneak into our field ...
And I "wait" only after a sound has played, long enough to give a suitable "pause".

Have fun!

Re: Recognizing character "-"

Posted: Sun Feb 28, 2021 12:43 pm
by oldummy
Hence my userid
Thanks to all. I was thinking I may have posted a little too soon,

Re: Recognizing character "-"

Posted: Sun Feb 28, 2021 1:02 pm
by bogs
Heh, well, I dunno about too soon, but if you want some purely graphical input, I'd stick with the underscores instead of the dashes for visual representation :D

Re: Recognizing character "-"

Posted: Sun Feb 28, 2021 5:34 pm
by stam
May be nothing at all to do with your issue, but be aware that especially on Windows there is a difference between a minus sign and a hyphen (the latter being a bit more emphasised and wider), and often a “space” & minus & “space” will autocorrect to a minus sign to a hyphen, so code that relies on the former will fail...