Page 1 of 2
changing location of objects in group doesn't work
Posted: Thu Jun 06, 2013 4:52 am
by makeshyft
Hi everyone,
I have a scriupt that creates a group and then I create a objects in the group.
When I try to set the "loc" of the object it does not work, it snaps to the top left corner.
I've tried just about everything ... I open the group for editing (start editing), but on ending the editing snaps it back to the top left corner again.....
Here is my code,
Code: Select all
//create the group, set size & properties
create group "LocalUserListGroup"
set the opaque of it to "true"
set the vscrollbar of it to "true"
//set the width of it to 500
//set the height of it to 590
//set loc of it to "372,455"
set the backgroundcolor of it to "55,55,55"
set lockLoc of it to true
set the innerglow["color"] of it to "0,0,0"
set the innerglow["opacity"] of it to 150
set the innerglow["size"] of it to 20
put it into grouplongid
//draw avatars, custom colored frames and names
local FirstLocx
local FirstLocy
local CurrentLocx
local CurrentLocy
global LocalUsersArray
set lockLoc of grouplongid to false
start editing group "LocalUserListGroup"
// IMAGE
create image LocalUsersArray[1]["User ID"]
set the name of it to LocalUsersArray[1]["User ID"]
set the width of it to 150
set the height of it to 150
set the loc of it to "100,400"
set lockLoc of it to true
set the filename of it to LocalUsersArray[1]["User Avatar"]
stop editing
set the width of grouplongid to 500
set the height of grouplongid to 590
set loc of grouplongid to "372,455"
//set the lockScreen to false
What am I doing wrong ?Thank you for any help.
[Solved] changing location of objects in group doesn't work
Posted: Thu Jun 06, 2013 5:07 pm
by makeshyft
To anyone who comes across this problem in the future.
You can use the move command to move around objects inside of a group.
Re: [Solved] changing location of objects in group doesn't w
Posted: Thu Jun 06, 2013 6:12 pm
by Klaus
makeshyft wrote:To anyone who comes across this problem in the future.
You can use the move command to move around objects inside of a group.
Sure you can move object inside of groups!
What made you think you can't?
Sorry, don't understand what this has to do with your problem?
Re: changing location of objects in group doesn't work
Posted: Thu Jun 06, 2013 6:40 pm
by jacque
Don't open the group for editing. When you set the editbackground to false afterward, the group will resize to encompass the objects within it, which can change their relative placement. Just set the locations of the objects directly, and ignore whether they are inside a group or not.
Object locations will always be relative to the top left corner of the card, even if they are inside a group.
Re: changing location of objects in group doesn't work
Posted: Thu Jun 06, 2013 10:03 pm
by makeshyft
Thank you Jacque,
and Klaus, it didn't work when I tried moving objects by setting its "loc" property. It only worked with the move command, which I didn't know, but now i know.
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 10:11 am
by Klaus
Hi Tom,
sorry, don't get this? I have been working with Livecode (and its ancestors) since 1999 and "set the loc of XYZ to X,Y" NEVER failed to work for me.
What am I missing?
Best
Klaus
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 3:56 pm
by makeshyft
Hmmm.....I will try it again..... but I spent a good hour on it trying to set the loc of an object inside a group and it didn't move....when I had the loc of the group locked that is.
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 4:23 pm
by dunbarx
No way locking a group locks the objects within it. And even locking objects within that group, or any objects anywhere, does not prevent a script from resetting their loc. The property only locks out user dragging.
Craig Newman
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 6:04 pm
by bn
Tom,
what version of LiveCode are you using. There is something fishy going on.
I also get funny results using an adaption of your script. I used Tom's script to create a group and an image in that group. The image appears in the wrong place. And I can not set the loc of the image by script.
I append the stack. If someone could explain me what is going on I would be grateful.
Kind regards
Bernd
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 6:21 pm
by dunbarx
Bernd
Using 5.4.4.
Are you saying the line:
set the loc of image "myImage" to twhere -- in btn "setLocationOfImageTo300_400"
does not work?
Mine does. Though you have to change the coordinates, since they were preset to "300,400" when the group was created, and the button sets to the same ones.
Also, could you be just a little more descriptive when setting the names of your buttons? That one above was cryptic.
Craig Newman
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 6:40 pm
by bn
Craig,
sorry for the "cryptiness"
If, after creating the group + image by button "createGroupMakeShyft", you look at the group location, which is set to 300,400 by script and the image location which is also set to 300,400 by script but appears at the topLeft of the group then the script fails to set the image to 300,400.
In the field you see the actual location of image "myImage" after pressing button "setLocationOfImageTo300_400". Actually I can not change the location of the image by script at all. Just as Tom described.
Or are you saying that when you press button "createGroupMakeShyft" the image "myImage" is located in the middle of the group at 300,400? That is not what I see.
I tried this with Livecode 5.5.2, 5.5.4 and 6.0.2 always the same.
Thanks for looking into this
Kind regards
Bernd
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 6:46 pm
by jacque
Interesting sample stack. The problem is the vscroll of the group. If it's set the odd behavior occurs. When I comment out that line, it works as expected.
It looks like a bug that needs to be reported.
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 6:58 pm
by FourthWorld
FWIW, if you set the boundingRect of the group to the rect of the group, the problem goes away, even with the scrollbar present.
I've seen a few cases where the boundingRect helps with object positioning withing groups, so there may be some non-obvious logic at play here that might mean it's not a bug but an intended feature, or at least a buggy side-effect of an intended feature.
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 7:39 pm
by dunbarx
I was focused on whether the image could be set by script. It can, but there is indeed a wierdness.
Richard, setting the bounding rectangle to anything but empty solves the problem.
Jacques is right about the vScroll.
Craig
Re: changing location of objects in group doesn't work
Posted: Fri Jun 07, 2013 7:48 pm
by makeshyft
Hmm.... I will play around with this some more and try to nail it down, and work with the bounding rect. I did find a workaround for this, but I would prefer cleaner code.
Thanks you guys for taking the time to look at this.