Error using groups: "Chunk: source is not a container"

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Error using groups: "Chunk: source is not a container"

Post by palanolho » Mon Jun 17, 2013 9:32 am

Greetings everyone.

I'm doing a scrip to resize all controls inside a group based on a slider. However, I'm getting an "Chunk: source is not a container" error and don't understand why.
(I'll highlight the error bellow)

Maybe someone can help me?

here's my script:

script on SLIDER

Code: Select all

On scrollbarDrag
     put the thumbPosition of me into field "zoomValue"
     put the thumbPosition of scrollbar "zoomSlider" / 100 into zfactor
     ResizeGroupContentByFactor (group "game_content_area", zfactor)     -- ## Error occurs in this line ###
end scrollbarDrag
script on STACK

Code: Select all

-- resize play area components
Function ResizeGroupContentByFactor cGroup, zFactor
     lock screen
     put GetGroupElements(group cGroup) into eArray
     put the number of lines of (the keys of eArray) into nrElems
    
     repeat with i = 1 to nrElems
          put the MesDim of control eArray[i] into tDim
          put round(item 1 of tDim * zFactor) into tW2
          put round(item 2 of tDim * zFactor) into tH2
          set the width of control eArray[i] to tW2
          set the height of control eArray[i] to tH2
     end repeat
    
end ResizeGroupContentByFactor

-- Get all Elementos of a Group
Function GetGroupElements cGroup
   put 1 into i
   put the number of controls of group cGroup into nrElems
   put empty into tArray
  
   repeat for (nrElems) times
      put the name of control i of group cGroup into line i of tArray
      add 1 to i
   end repeat
  
   return tArray
  end GetGroupElements
Many thanks for any help
- Miguel

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Error using groups: "Chunk: source is not a container"

Post by Mark » Mon Jun 17, 2013 10:22 am

Hi Miguel,

The easy way is

Code: Select all

     resizeGroupContentByFactor "game_content_area", zfactor
The complicated way is to replace all references to group cGroup in the ResizeGroupContentByFactor function with cGroup (i.e. delete "goup") and use the following syntax:

Code: Select all

     resizeGroupContentByFactor the long id of "game_content_area", zfactor
The latter is slightly more fail-safe, which is useful when your project grows and you decide to move the ResizeGroupContentByFactor function to a different place in your project (e.g. a library stack).

Why do you use a function? Your function doesn't return anything and you are calling the function as were it a command.

Change the line

Code: Select all

Function ResizeGroupContentByFactor cGroup, zFactor
into

Code: Select all

on resizeGroupContentByFactor cGroup, zFactor
Note that in LiveCode, we don't start command and function names with capitals. You can, but it isn't very common to do so.

Kind regards,

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

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

Re: Error using groups: "Chunk: source is not a container"

Post by jmburnod » Mon Jun 17, 2013 10:31 am

Hi Miguel,

Your GetGroupElements function doesn't return an array but you can use it like this:

Code: Select all

--function resizeGroupContentByFactor cGroup, zFactor
on resizeGroupContentByFactor cGroup, zFactor
   lock screen
   put GetGroupElements(group cGroup) into eArray
   put the number of lines of eArray into nrElems
   repeat with i = 1 to nrElems 
      put line i of  eArray into tControl
      put the loc of control tControl into tOldLoc
      put the MesDim of control tControl into tDim
      put round(item 1 of tDim * zFactor) into tW2
      put round(item 2 of tDim * zFactor) into tH2
      set the width of control tControl to tW2
      set the height of control tControl to tH2
   end repeat
end resizeGroupContentByFactor
Best regards
https://alternatic.ch

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Error using groups: "Chunk: source is not a container"

Post by Mark » Mon Jun 17, 2013 10:42 am

Hi,

Just like in my previous post,

Code: Select all

GetGroupElements(group cGroup)
won't work either. It'll have to be

Code: Select all

GetGroupElements(cGroup)
where cGroup needs to contain only the name of the group and not a reference to the group itself. You can, however, replace the name of the group with the long id of the group and change the GetGroupElements by deleting the word "group" from all group references.

Kind regards,

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

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Error using groups: "Chunk: source is not a container"

Post by palanolho » Mon Jun 17, 2013 9:09 pm

OK, I made some modifications as suggested and it almost works (... almost). Some of the suggestions give me errors that I (still) don't understand.

Code: Select all

-- CODE ON SLIDER

on scrollbarDrag
     put the thumbPosition of me into field "zoomValue"
     put the thumbPosition of scrollbar "zoomSlider" / 100 into zfactor
     resizeGroupContentByFactor "game_content_area", zfactor
end scrollbarDrag

-- CODE ON STACK

-- resize play area components
on resizeGroupContentByFactor cGroup, zFactor
     lock screen
     put getGroupElements (cGroup) into eList
     put the number of lines of eList into nrElems
     
     repeat with i = 1 to nrElems
          put line i of  eList into tControl
          -- put the loc of control tControl into tOldLoc
          put the MesDim of control tControl into tDim
          put round(item 1 of tDim * zFactor) into tW2
          put round(item 2 of tDim * zFactor) into tH2
          set the width of control tControl to tW2
          set the height of control tControl to tH2
     end repeat
     
end resizeGroupContentByFactor

-- Get all Elementos of a Group
function getGroupElements cGroup
     put the number of controls of group cGroup into nrElems
     put empty into tList
     
     repeat with i = 1 to nrElems
          put the name of control i of group cGroup into line i of tList
     end repeat
     
     return tList
end getGroupElements

The following errors occur:

(1)
resizeGroupContentByFactor the long id of "game_content_area", zfactor
(scrollbar "zoomSlider": execution error at line n/a (Chunk: error in object expression) near "game_content_area", char 1)

I took the "the long id of" from the code and it passes with no error. So, I took it out to be able to continue, but would like to understand Why this error if, as you indicated, It's supposed to work.

(2)
I'm doing step by step to debug and found out that the line "put the MesDim of control tControl into tDim" is doing nothing. after executing it,the var tDim stays empty

(3)
the script starts resizing the controls (yey) but .. it gives me an error when it reaches the control "image id 1469" and I dont understanding why.
(stack "main_app": execution error at line 9 (Chunk: no such object) near "image id 1469", char 23)

the list of controls has the following:
graphic "play_area_bg"
image id 1469
image id 1470
image id 1471
image id 1472
button "Button"


Any ideas? :(

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

Re: Error using groups: "Chunk: source is not a container"

Post by jmburnod » Mon Jun 17, 2013 10:20 pm

Hi Miguel,
the list of controls has the following:
graphic "play_area_bg"
image id 1469
image id 1470
image id 1471
image id 1472
button "Button"
First ou have to give a name to each control and change your getGroupElements function

Code: Select all

     repeat with i = 1 to nrElems
        --  put the name of control i of group cGroup into line i of tList
          put the SHORT name of control i of group cGroup into line i of tList
     end repeat
The name of a control for the field "myField" include the type of control = field "myField
In your resizeGroupContentByFactor handler tControl must be = the short name of control i
put the MesDim of control tControl into tDim" where tControl = "graphic "play_area_bg", the result is nothing
Yes, MesDim is a customproperty which store the original Width and Height of each concerned control


Kind regards
Jean-Marc
https://alternatic.ch

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Error using groups: "Chunk: source is not a container"

Post by palanolho » Mon Jun 17, 2013 10:33 pm

Hi Jean-Marc

the short name thing worked, thanks :)

about the MesDim... how can i define that value to a control that i have already in my stack ???

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

Re: Error using groups: "Chunk: source is not a container"

Post by jmburnod » Mon Jun 17, 2013 10:54 pm

Hi Miguel,
about the MesDim... how can i define that value to a control that i have already in my stack

Code: Select all

-- define the MesDim customprop of each control of group cGroup
on defineCustomPropWH cGroup
   put getGroupElements (cGroup) into eList
   put the number of lines of eList into nrElems
   repeat with i = 1 to nrElems
      put line i of  eList into tControl
      put  the width of control tControl into tW
      put  the height of control tControl into tH
      set the MesDim of control tControl to tW & "," & tH
   end repeat
end defineCustomPropWH
https://alternatic.ch

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Error using groups: "Chunk: source is not a container"

Post by palanolho » Mon Jun 17, 2013 10:59 pm

Is it possible to define it manually in the control inspector ?

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

Re: Error using groups: "Chunk: source is not a container"

Post by jmburnod » Mon Jun 17, 2013 11:04 pm

Yes,
Check customproperties menu in the control inspector
https://alternatic.ch

palanolho
Posts: 122
Joined: Sat Apr 27, 2013 11:40 pm

Re: Error using groups: "Chunk: source is not a container"

Post by palanolho » Tue Jun 18, 2013 9:20 am

Now its working yey :D

Thanks alot guys for all your help

Cheers

- Miguel

Post Reply