group an unknown number of groups

Getting into LiveCode for iOS? Ask your questions here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
Peter@multidesk.se
Posts: 125
Joined: Fri Oct 14, 2011 6:53 am

group an unknown number of groups

Post by Peter@multidesk.se » Mon Nov 19, 2018 7:50 am

I have an unknown number of groups that I need to group into one group

Any suggestions on how to do this?

Probably simple but I'm stuck!

Code: Select all

on openCard
   put yLine into tTemp
   repeat with x = 1 to tCreate 
      clone group "template" of me 
      set the name of it to (carLine & x)
      if x = 1 
      then  
         set the loc of group (carLine & x) to xLine, yLine
      else
         set the loc of group (carLine & x)  to xLine, (tTemp + 44)
         add 44 to tTemp
      end if
   end repeat
   
   -- Here I need to group all the groups I created above into one group
   
end openCard

///Peter
/*Whats all the fuss with c# ?*/

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2030
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: group an unknown number of groups

Post by [-hh] » Mon Nov 19, 2018 8:22 am

You could try the following.

Code: Select all

repeat with x = 1 to tCreate 
   ...
   put " and group " & (carLine & x) after doJob
end repeat
put "group" into word 1 of doJob
do doJob
Or you could directly group the objects (use copy instead of clone)

Code: Select all

if there is no grp "newGroup" then create grp "newGroup"
repeat with x = 1 to tCreate 
   copy grp "template" to grp "newGroup"
   set the name of grp id it to (carLine & x)
   ...
shiftLock happens

Peter@multidesk.se
Posts: 125
Joined: Fri Oct 14, 2011 6:53 am

Re: group an unknown number of groups

Post by Peter@multidesk.se » Tue Nov 20, 2018 12:06 pm

Just what I needed!

I was not familiar with the command "do" :oops: , definitely useful for various projects!

Thanks


///Peter
/*Whats all the fuss with c# ?*/

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

Re: group an unknown number of groups

Post by Klaus » Tue Nov 20, 2018 12:11 pm

Hi Peter,

maybe this is a bit more understandable (and my favourite!):

Code: Select all

...
## Select all groups just like with the mouse and SHIFT-key, but via script:
repeat with x = 1 to tCreate 
      set the selected of grp (caLine & x) to TRUE
end repeat

## All of your groups are selected not and we can simply issue this fine command:
group

## De-select everything and here you go :-)
select empty
...
Best

Klaus

Post Reply

Return to “iOS Deployment”