Referencing a just scripted grouping?

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
melristau
Posts: 56
Joined: Tue Jul 14, 2015 5:15 pm
Contact:

Referencing a just scripted grouping?

Post by melristau » Mon Aug 01, 2016 11:19 pm

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
rebuilding visual programming app originally created in 1993 as Hypercard stack

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Referencing a just scripted grouping?

Post by jmburnod » Mon Aug 01, 2016 11:30 pm

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
https://alternatic.ch

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

Re: Referencing a just scripted grouping?

Post by dunbarx » Tue Aug 02, 2016 3:24 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Referencing a just scripted grouping?

Post by FourthWorld » Tue Aug 02, 2016 9:36 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 1232
Joined: Thu Apr 11, 2013 11:27 am

Re: Referencing a just scripted grouping?

Post by LCMark » Mon Aug 08, 2016 10:21 am

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.

Post Reply