1

I am making a two-player hangman game, and I have set a limit of 10 characters which is working fine:

on keyDown
 if the length of me = 10 then
  beep
 else
  pass keyDown
 end if
end keyDown

However, when I try to limit the character input to only lowercase characters, nothing seems to happen. I can still type any character I want.

on keyDown inkey
 if inkey is in "abcdefghijklmnopqrstuvwxyz" then
  pass keyDown
 else
  beep
 end if
end keyDown

How do I fix this? Thankyou.

CoopDaddio
  • 577
  • 1
  • 5
  • 20

1 Answers1

0

Don't pass the keyDown message. Instead, put the value of the parameter after the field.

on keyDown theKey
  if len(the text of me) >= 10 then
    beep
  else
    put toLower(theKey) after me
  end if
end keyDown

The problem occurs, because LiveCode considers lower case and upper case characters as equal:

put ("a"="A")

returns true. Another way to solve this is to set the caseSensitive to true. If you add this line

set the caseSensitive to true

to the beginning of your script, it will do exactly what you want.

Mark
  • 2,380
  • 11
  • 29
  • 49