Execute script after cloning an object ?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Execute script after cloning an object ?

Post by raugert » Thu May 31, 2018 12:31 am

I'm building an application that lets the user clone objects in "pointer mode" using the (opt-click-drag). I would like to add the ID of the newly created object to a datagrid. I'm checking to see if the option key is down and adding the ID to the datagrid but it adds the ID of the original button... The script below is in the original button. I'm pretty sure I'm going about this the wrong way :? Is there another way to trap the opt-click-drag message ?

Code: Select all

on checkOptionKey
   if the eventOptionKey is down then
         select last button
         put the dgNumberOfLines of group "Datagrid" into theLineNo
         put the dgDataOfLine[theLineNo] of group "Datagrid" into theDataA
         put the id of selectedObject into theDataA["ID"]
         dispatch "AddData" to group "Datagrid" with theDataA, theLineNo +1
      end if
end checkOptionKey
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Execute script after cloning an object ?

Post by mrcoollion » Thu May 31, 2018 7:48 am


Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Execute script after cloning an object ?

Post by Klaus » Thu May 31, 2018 9:35 am

Try:

Code: Select all

on checkOptionKey
   if the eventOptionKey is down then
         ## select last button
         put the dgNumberOfLines of group "Datagrid" into theLineNo
         put the dgDataOfLine[theLineNo] of group "Datagrid" into theDataA
         put the id of THE LAST BUTTON into theDataA["ID"]
         dispatch "AddData" to group "Datagrid" with theDataA, theLineNo +1
      end if
end checkOptionKey
If that does not work, please show us the script which CLONEs the button.

Usually after a cloning the variable IT contains the long ID of the cloned object.
So if you store IT in a variable or custom property you should get this working.

raugert
Posts: 112
Joined: Thu May 26, 2016 9:30 pm
Location: Winnipeg, Canada

Re: Execute script after cloning an object ?

Post by raugert » Fri Jun 01, 2018 3:58 am

thanks Klaus,

That seems to work OK.

Much appreciated,
Richard
Livecode Indy 9.6.11 (Stable)
MacOS Sonoma 14.2
Xcode 15.0.1 SDK 17.0

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”