Recognizing character "-"
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Recognizing character "-"
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?
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 "-"
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


Re: Recognizing character "-"
Hi,
just checked out of curiosity. This works:
"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!
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
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!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: Recognizing character "-"
Hence my userid
Thanks to all. I was thinking I may have posted a little too soon,
Thanks to all. I was thinking I may have posted a little too soon,
Re: Recognizing character "-"
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 


Re: Recognizing character "-"
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...