Hi again,
I need help deleting clones on preOpenCard
This is the scenario:
On my card, I have a group containing a graphic and a field. I also have a button that creates clones of the whole group. Everytime a group is cloned, it receives a different name. This is my code.
on mouseUp
clone group Goval
repeat with i = 1 to the number of groups in card "graphics"
set the name of the last group to "Clone" & i
set the name of the last graphic to "oval" & i
set the name of the last field to "topic" & i
set the location of last group to 157, 176
end repeat
Now, I need to make sure that eveerytime the end user opens this card, there won't be any clone. This is the part that is not working.
on preOpenCard
if exists group ("Clone" & i) then
delete group "Clone" & i
end if
if exists (graphic "oval" & i) then
delete graphic "oval" & i
end if
if exists (field "topic" & i) then
delete field "topic" & i
end if
end preOpenCard
This is the message I get:
card "Graphics": compilation error at line 6 (Function: missing '('), char 7
Any suggestions?
Thanks
Marta
deleting clones
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Hi Marta,
I believe that you want something like this:
Best,
Mark
I believe that you want something like this:
Code: Select all
on mouseUp
clone group Goval
repeat with i = 1 to the number of groups in card "graphics"
set the name of the last group to "Clone" & i
set the name of the last graphic to "oval" & i
set the name of the last field to "topic" & i
set the location of last group to 157, 176
end repeat
end mouseUp
on preOpenCard
repeat with i = 1 to the number of groups in card "graphics"
if exists(group ("Clone" & i)) then
delete group ("Clone" & i)
end if
if exists(graphic ("oval" & i)) then
delete graphic ("oval" & i)
end if
if exists(field ("topic" & i)) then
delete field ("topic" & i)
end if
end repeat
end preOpenCard
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- VIP Livecode Opensource Backer
- Posts: 4036
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Marta,
this would compile but not workbecause rev does not know what i is in a preopencard handler without a repeat loop which Mark did. Then the i is a variable and is filled with a number. Otherwise it would only be i and evalutate to clonei ovali topici.
in your mouseUp handler you could also sayno need for a repeat loop here since you clone the group and you just want the numer of groups and this number will be part of the name. If you do it in a repeat loop you will rename your last group and all that is in it to clone1, clone2 up to the actual number of groups and then it will be allright but you cycled through all the names.
In your preopenstack handler you could sayhere you look for clone as part of the name and if true then you delete that group, Since the graphic and the text field are part of that group they are gone with the group. No need to delete them individually. The trick here is to count backwards. You start with the number of groups and count down to 1. This is because you delete groups which changes the numbering scheme of the groups. If you have 6 groups and you delete group 4 then group 5 becomes group 4 and group 6 becomes 5. If you count down to 1 then it does not matter if you delete group 4 of 6, the next group you are looking at is group 3 and the fact that the numbering has changed does not bother you.
regards
Bernd
this would compile but not work
Code: Select all
if exists (group ("Clone" & i)) then
delete group ("Clone" & i)
end if
if exists (graphic ("oval" & i)) then
delete graphic "oval" & i
end if
if exists (field ("topic" & i)) then
delete field ("topic" & i)
end if
in your mouseUp handler you could also say
Code: Select all
on mouseUp
clone group "Goval"
put the number of groups of this card into tGroupNo
set the name of last group to "Clone" & tGroupNo
set the name of the last graphic to "oval" & tGroupNo
set the name of the last field to "topic" & tGroupNo
set the location of last group to 157, 176
end mouseUp
In your preopenstack handler you could say
Code: Select all
on preopencard
put the number of groups of this card into tCountOfGroups
repeat with i = tCountOfGroups down to 1
if the short name of group i contains "clone" then delete group i
end repeat
end preopencard
regards
Bernd