Accessing grouped objects from card behavior script

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: heatherlaine, Klaus, FourthWorld, kevinmiller

Post Reply
beetlejooce
Posts: 8
Joined: Mon Apr 30, 2012 1:51 am

Accessing grouped objects from card behavior script

Post by beetlejooce » Thu Sep 20, 2018 3:26 am

Hi all,

I'm trying to remove some text in some grouped text fields, from a script located in the cards behavior script (I'm using the Levure framework).

Sample code:

Code: Select all

on openCard
    local i = 0
    start editing group "grpIcons" of card "preferences" of stack "main_window"
    -- Clear preferences
    repeat while i < 24
        local tPreferenceName
        local tPreferenceValue
        local tPreferenceField
        put "ICONS Custom" && i into tPreferenceName
        put "fldCustom" & i into tPreferenceField 
        put tPreferenceValue into fld tPreferenceField of group "grpIcons" of card "preferences" of stack "main_window"
        put i + 1 into i
    end repeat
    stop editing group "grpIcons" of card "preferences" of stack "main_window"
end openCard
I can see the group being opened for editing in the ide, but get a bug at "put tPreferenceValue into fld tPreferenceField....." of "No such object".

I've tried leaving off the "of group "grpIcons" of card "preferences" of stack "main_window"" as well as just leaving off the "of group "grpIcons"", to no avail. The posted script works just fine without the objects being grouped (without the edit group calls obviously).

Where did I go wrong?
Thanks in advance for any assistance.

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2225
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Accessing grouped objects from card behavior script

Post by jmburnod » Thu Sep 20, 2018 6:49 am

Hi,
I believe start editing group change message path
Why do you need editing group ?
Best regards
Jean-Marc

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6154
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Accessing grouped objects from card behavior script

Post by FourthWorld » Thu Sep 20, 2018 7:52 am

Jean-Marc is spot on: editing backgrounds is a mode provided to assist certain layout tasks within the IDE. Nothing prevents you from using it in your scripts, but things are usually simpler without it.

And since you're using a behavior, "me" will refer to the object the script is attached to, which will simplify referencing controls within the card.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

beetlejooce
Posts: 8
Joined: Mon Apr 30, 2012 1:51 am

Re: Accessing grouped objects from card behavior script

Post by beetlejooce » Thu Sep 20, 2018 3:49 pm

I originally had some text sizing code in that handler but removed it for testing, Hence the "start editing group".

I've removed that and tried your suggestion of "me", and all of the stuff from my previous post. Same error. I finally just scrapped it and started over. Of course it works just fine now.

Thanks for the info and suggestions.

Out of curiosity, how does the message path change with "start editing group"? I've always been kind of mystified by how the message path changes and what changes it. I book marked your extending the message path page a loooong time ago!

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2225
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Accessing grouped objects from card behavior script

Post by jmburnod » Thu Sep 20, 2018 5:23 pm

I don't know how LC does this but why i know why i have thought that message path change with editing group.
If you have an object script in a group which calls a card script and you edit the group the first line "go to definition" of contextual menu of script editor looks grey for your object script.

Jean-Marc

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 6154
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Accessing grouped objects from card behavior script

Post by FourthWorld » Thu Sep 20, 2018 6:02 pm

beetlejooce wrote:
Thu Sep 20, 2018 3:49 pm
I've removed that and tried your suggestion of "me", and all of the stuff from my previous post. Same error. I finally just scrapped it and started over. Of course it works just fine now.
What changed that made it work?
Out of curiosity, how does the message path change with "start editing group"? I've always been kind of mystified by how the message path changes and what changes it.
Everyone is. It's not commonly needed in delivering the end-user experience, so very few people ever have to script for it.

In essence, it works in scripting how it looks in appearance: controls outside the group being edited become unaddressable, and those within the group are temporarily not within the group, since the group and everything outside of it is not there while that mode is active.

Highly specialized, rarely needed, almost always a simpler, cleaner way to do anything other than the one thing that feature was provided for, allowing developers to handle certain layout tasks within the IDE.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4619
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Accessing grouped objects from card behavior script

Post by jacque » Fri Sep 21, 2018 5:00 pm

When you edit a group, LC creates a temporary card in RAM and copies the objects in the group to it. After you stop editing it copies the revised objects back into the original group and deletes the temporary card.

I don't know what the message path is, or even if there is one beyond the card itself. It isn't clear whether the temporary card is even part of the original stack or not. Group editing is a GUI aid but isn't really intended for uses outside of development since it's possible to do most editing without going into group editing mode.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5528
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Accessing grouped objects from card behavior script

Post by dunbarx » Fri Sep 21, 2018 5:19 pm

@ Beetlejooce

You do know about the menu "Edit group" in the menubar, right?

This probably does mostly, if not exactly what the "start editing" command drums up.

Craig Newman

beetlejooce
Posts: 8
Joined: Mon Apr 30, 2012 1:51 am

Re: Accessing grouped objects from card behavior script

Post by beetlejooce » Sun Sep 23, 2018 3:56 am

I'm not really sure what "fixed" it, as I scrapped it and restarted the IDE. Either one of those actions may have been responsible. I know I should have tried each one individually, but I got hasty!

My reason for meddling with "edit group" was really just for laziness. I set the font to bold for the group, and didn't want to have to touch each object inside it to set it to plain. I've since done just that, and have no further issues (at this time!) with my access to group objects.

Thank you for the tips about the message path!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”