Page 1 of 1

Small boys teaching me LiveCode

Posted: Fri Oct 08, 2021 5:19 pm
by richmond62
Indeed . . .

I got this via Viber today from an 11 year old:
-
SShot 2021-10-08 at 19.14.29.png
-
Which "threw me off" quite a bit as I ALWAYS (in my EFL programs) use a Tick image for end users to check a field's contents.

I had never used the RETURN key, and had never worked out how to.

SO . . . to the much-maligned built-in Dictionary and found on ReturnInField, which, was, frankly, like being handed the keys to
the Holy Kingdom on a plate:

Code: Select all

on returnInField
   if fld "ff" contains "black" then
      set the vis of img "YES" to true
      set the vis of img "NO" to false
   else
      set the vis of img "YES" to false
      set the vis of img "NO" to true
   end if
   if fld "ff" is empty then
      set the vis of img "YES" to false
      set the vis of img "NO" to false
   end if
end returnInField
-
SShot 2021-10-08 at 19.10.52.png
-
SShot 2021-10-08 at 19.11.08.png

Re: Small boys teaching me LiveCode

Posted: Fri Oct 08, 2021 5:21 pm
by richmond62
SShot 2021-10-08 at 19.11.14.png
-

Re: Small boys teaching me LiveCode

Posted: Sat Oct 09, 2021 9:39 am
by richmond62
tickkkk.jpg
-
Personally I tend to use a 'Tick' button rather than returnInField. 8)

Re: Small boys teaching me LiveCode

Posted: Sat Oct 09, 2021 4:26 pm
by richmond62
I wonder if it is possible to differentiate between the ENTER and the RETURN keys?
-
keeze.jpg
-
Of course one could differentiate by using rawKey codes:

ENTER: 65421

RETURN: 65293

BUT that misses the point somewhat.

The Dictionary offers enterKey, and enterInField.

Hitting the ENTER key in a field yields a CR (carriage return) character unless one traps for it specifically.

Code: Select all

on enterInField
   if fld "ff" contains "black" then
      set the vis of img "YES" to true
      set the vis of img "NO" to false
   else
      set the vis of img "YES" to false
      set the vis of img "NO" to true
   end if
   if fld "ff" is empty then
      set the vis of img "YES" to false
      set the vis of img "NO" to false
   end if
end enterInField

Re: Small boys teaching me LiveCode

Posted: Sun Oct 10, 2021 5:25 pm
by jacque
The Dictionary offers enterKey, and enterInField.
And also returnKey and returnInField. The easiest way to differentiate is to use both return and enter variants in the script.

Re: Small boys teaching me LiveCode

Posted: Sun Oct 10, 2021 6:00 pm
by Klaus
ELSE also covers -> if fld "ff" = empty

Code: Select all

on enterInField
   if fld "ff" contains "black" then
      set the vis of img "YES" to true
      set the vis of img "NO" to false
   else
      set the vis of img "YES" to false
      set the vis of img "NO" to true
   end if
end enterInField

Re: Small boys teaching me LiveCode

Posted: Sun Oct 10, 2021 6:03 pm
by richmond62
ELSE also covers -> if fld "ff" = empty
If you read my code more carefully you'll see that a word that is not 'black' gives
the 'No' image, while an empty field gives no image at all.

Re: Small boys teaching me LiveCode

Posted: Sun Oct 10, 2021 6:16 pm
by Klaus
Sorry, I bow my head in shame! :oops:

Re: Small boys teaching me LiveCode

Posted: Sun Oct 10, 2021 6:20 pm
by richmond62
Sit opposite your teacher, learn everything he knows,
then kill him and take his place. 8)