Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
mrcoollion
- Posts: 738
- Joined: Thu Sep 11, 2014 1:49 pm
Post
by mrcoollion » Mon Jan 24, 2022 4:44 pm
Hi All,
I am having trouble with the below code. The object is : when a user left-clicks this button the button copy's itself, places the button at a placeholder (which is a graphic object) and renames itself. when a user right-clicks the botton removes itself if the name of the button starts with an A.
I cannot find what I am doing wrong in the following code
Code: Select all
on mouseup pButtonNumber
if pButtonNumber = 1 -- (left Mouse button)
then
copy me to grp "grp_BuyBlock" of this card
put it into tNewObjectID
set the topleft of button id tNewObjectID to the topleft of graphic "PlacementPoint"
set the short name of btn tNewObjectID to "A_" & the short name of me
end if
--
if pButtonNumber = 3 -- (Right Mouse button)
then
if the the first character of the label of me is "A"
then
delete me
else
exit mouseup
end if
end if
end mouseup
Regards,
Paul
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10339
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Jan 24, 2022 4:56 pm
Hi.
Works fine for me.
At first I thought that the inclusion of the word "id" in your handler might have caused a problem, since the value of the variable "it" is not really an ID, but rather an object reference. But LC seems to know better, and works regardless of whether that word is there or not.
Craig
Last edited by
dunbarx on Mon Jan 24, 2022 4:59 pm, edited 1 time in total.
-
Klaus
- Posts: 14206
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Mon Jan 24, 2022 4:58 pm
Hi Paul,
quick guess, you cannot delete an object whichs script is currently running!
So I think the line "delete me" is the problem, right? Try something like:
Code: Select all
...
if the the first character of the label of me is "A" then
put the long ID of me into tObject
send "delete tObject" to this cd in 1
## Not neccessary, since this is the end of the script anyway!
## else
## exit mouseup
end if
...
Best
Klsud
-
matthiasr
- VIP Livecode Opensource Backer

- Posts: 195
- Joined: Sat Apr 08, 2006 7:55 am
-
Contact:
Post
by matthiasr » Mon Jan 24, 2022 4:58 pm
Here it also doesn't work.
Maybe the button cannot deleted while its script is running.
So replace the line
with
Code: Select all
send "DELETEBTN" && THE ID OF ME TO THIS CARD in 50 milliseconds
and add the following script to the card script
Code: Select all
ON DELETEBTN pID
delete btn id pID
end DELETEBTN
-
dunbarx
- VIP Livecode Opensource Backer

- Posts: 10339
- Joined: Wed May 06, 2009 2:28 pm
Post
by dunbarx » Mon Jan 24, 2022 5:02 pm
Ah,
Did not read fully, to see that the issue was with the second part of the handler.
Craig