Page 1 of 1
Referencing a just scripted grouping?
Posted: Mon Aug 01, 2016 11:19 pm
by melristau
How do I reference the name of a group just created by script?
Code: Select all
on mouseUp
clone btn "seed"
set the name of it to "Pn"
set the loc of it to 1500,550
set the icon of it to "Pn"
clone btn "seed"
set the name of it to "iiii"
set the loc of it to 1500,550
set the icon of it to "iiii"
group btn "Pn" and btn "iiii"
--set the name of it to "bundle"-- not correct
end mouseUp
Re: Referencing a just scripted grouping?
Posted: Mon Aug 01, 2016 11:30 pm
by jmburnod
What about
Code: Select all
set the name of last group to "bundle"
instead
Code: Select all
--set the name of it to "bundle"-- not correct
Best regards
Jean-Marc
Re: Referencing a just scripted grouping?
Posted: Tue Aug 02, 2016 3:24 am
by dunbarx
All.
As of v.6x, the "last" keyword is not stable with groups. It works fine with all other controls. I left a user note under "last":
....The "last" keyword is not stable when referring to groups. So if one creates several groups, referencing the "last" group may not return the group actual ly created last. Using the "templateGroup" is a workaround, since when creating a new group one can, for example, set the name of the templateGroup to something unique, and be able to find the last group by name. Also, trapping the "newGroup" message with an appropriate script can be used to find the last group....
Craig Newman
Re: Referencing a just scripted grouping?
Posted: Tue Aug 02, 2016 9:36 pm
by FourthWorld
I asked about this on the discussion list, and was pointed to this enhancement request with a lively and detailed discussion:
http://quality.livecode.com/show_bug.cgi?id=8275
Also on the list, Jeanne DeVoto came up with a good way to identify a newly-created group in those cases where "last" may not refer to "most recently created": before issuing the group command, get the long ID of one of the objects being grouped, then after the group get the long ID of that group's owner.
Yep, a workaround, but not often needed and handy when it is.
Re: Referencing a just scripted grouping?
Posted: Mon Aug 08, 2016 10:21 am
by LCMark
I should point out here that 'last' never refers to 'most recently created' and never has - it always refers to the last object of that type on the card. So, if your card has the structure:
Code: Select all
card
button
group A
button
group B
button
field
group C
Then, even if you create a group in group A then 'the last group' will still refer to group C. Of course, in this case 'the last group of group A' should give what you need.
I think the problem here is that some control creation commands *do not* return the long id 'it'; meaning that you can't easily access the control you just created and have to write more script to work out what the id of the object you just created was.