customKeys and recalling the data in a key

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 744
Joined: Thu Sep 11, 2014 1:49 pm

customKeys and recalling the data in a key

Post by mrcoollion » Tue Apr 21, 2026 11:12 am

It has been a while that i have been on this forum, so hello to you all LiveCoder's :-).
I do come here for the following reason.

I thought it was a good idea to save fixed data within a menupick button using customKeys. However i cannot seem to get it working .
The code does not give me errors but also i do not get anything in field "TextField" . The target field "TextField" is made empty :shock: but no text that is kept in customKeys .

So here is the simple code for test. What do i do wrong ?

Code: Select all

on menuPick itemPicked
   switch itemPicked
      case "1st Text"
         put the customKeys["1st Text"] of me into fld "TextField"
         break
   end switch
end menuPick
Regards,

Paul

Klaus
Posts: 14314
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: customKeys and recalling the data in a key

Post by Klaus » Tue Apr 21, 2026 1:34 pm

Dag Paul,

to retrieve a CP with a name with more than one word, you need to use a variable to do so!
This works:

Code: Select all

on menuPick itemPicked
   switch itemPicked
      case "1st Text"
         get "1st text"
         put the IT of me into fld "TextField"
         break
   end switch
end menuPick
Groetjes
Klaus

mrcoollion
Posts: 744
Joined: Thu Sep 11, 2014 1:49 pm

Re: customKeys and recalling the data in a key

Post by mrcoollion » Tue Apr 21, 2026 2:09 pm

Never would have thought of this.

Dankjewel (Thank you) Klaus.

mrcoollion
Posts: 744
Joined: Thu Sep 11, 2014 1:49 pm

Re: customKeys and recalling the data in a key

Post by mrcoollion » Tue Apr 21, 2026 2:45 pm

Sorry Klaus, still does not work.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10488
Joined: Wed May 06, 2009 2:28 pm

Re: customKeys and recalling the data in a key

Post by dunbarx » Tue Apr 21, 2026 4:44 pm

I also cannot get the alternate form to give anything but empty. That alternate form is given as an example , but not listed in the property syntax, which is simply
put the customKeys of me into fld "TextField"
Craig

Klaus
Posts: 14314
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: customKeys and recalling the data in a key

Post by Klaus » Tue Apr 21, 2026 6:16 pm

Works here with a menu button, see screenshot.
I used the same example as Paul:

Code: Select all

on menuPick itemPicked
   switch itemPicked
      case "1st Text"
         get "1st text"
         put the IT of me
         break
   end switch
end menuPick
cp_from_menu.png
?

mrcoollion
Posts: 744
Joined: Thu Sep 11, 2014 1:49 pm

Re: customKeys and recalling the data in a key

Post by mrcoollion » Wed Apr 22, 2026 8:41 pm

I got it working.Added the following two menu items to a pulldown button
No clue why i did not get it working before. I added a new button and a new target field "TestTekst" and added the menu items below to the button .
1st Text
2nd Text

With the below code it worked

Code: Select all

on menuPick itemPicked
   switch itemPicked
      case "1st Text"
         get "1st text"
         put the IT of me into fld "TestTekst"
         break
      case "2nd Text"
         get "2nd Text"
         put the IT of me into fld "TestTekst"
         break
   end switch
end menuPick
Bedankt Klaus voor je hulp.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4215
Joined: Sun Jan 07, 2007 9:12 pm

Re: customKeys and recalling the data in a key

Post by bn » Thu Apr 23, 2026 10:38 am

I was intrigued by this thread because I am always a bit confused by addressing the custom properties.
@Paul
You could simplify the script of button to:

Code: Select all

on menuPick itemPicked
      put the itemPicked of me into field "testTekst"
end menuPick
Your first attempt did not work because you were addressing the "customKeys" in array fashion. CustomKeys is a list of the keys of the customProperties. CustomKeys is not an array.

If you would want to address the arrary you could do:

Code: Select all

on menuPick itemPicked
   put the customProperties  of me into tCustomA
   put tCustomA[itemPicked] into field "testTekst"
end menuPick
Kind regards
Bernd

Klaus
Posts: 14314
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: customKeys and recalling the data in a key

Post by Klaus » Thu Apr 23, 2026 11:33 am

mrcoollion wrote:
Wed Apr 22, 2026 8:41 pm
I got it working.Added the following two menu items to a pulldown button
No clue why i did not get it working before. I added a new button and a new target field "TestTekst" and added the menu items below to the button .
1st Text
2nd Text
With the below code it worked

Code: Select all

on menuPick itemPicked
   switch itemPicked
      case "1st Text"
         get "1st text"
         put the IT of me into fld "TestTekst"
         break
      case "2nd Text"
         get "2nd Text"
         put the IT of me into fld "TestTekst"
         break
   end switch
end menuPick
Bedankt Klaus voor je hulp.
Graag gedaan! :-)

Post Reply