reference of controls in a variable

If you find an issue in LiveCode but are having difficulty pinning down a reliable recipe or want to sanity-check your findings with others, this is the place.

Please have one thread per issue, and try to summarize the issue concisely in the thread title so others can find related issues here.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
trevix
Posts: 387
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

reference of controls in a variable

Post by trevix » Sun Jun 12, 2016 5:51 pm

Someone can explain me why?

Code: Select all

on mouseUp
    repeat with U = 1 to the number of controls of this card
        put the abbrev ID of control U & cr after tListOfControls
    end repeat
    delete last char of tListOfControls
    
    ---THIS WORKS
    put  line 2 of tListOfControls into tAbbrevID
    put word 2 of the short name of tAbbrevID into tNumber
    
    --THIS ALSO WORKS
     put word 2 of the short name of (line 2 of tListOfControls) into tNumber
    
    --THIS DOEN'T WORK
     put word 2 of the short name of line 2 of tListOfControls into tNumber
end mouseUp
Thanks
Trevix
Trevix

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

Re: reference of controls in a variable

Post by FourthWorld » Sun Jun 12, 2016 6:08 pm

My tListOfControls may not be the same as yours. What is your line 2 that's causing the error to be thrown?
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/

trevix
Posts: 387
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: reference of controls in a variable

Post by trevix » Sun Jun 12, 2016 6:14 pm

See the script of btn "Button One"
Attachments
Test_1.livecode.zip
Click on btw "Button One"
(1.04 KiB) Downloaded 63 times
Trevix

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 168
Joined: Thu Apr 18, 2013 2:48 pm

Re: reference of controls in a variable

Post by livecodeali » Wed Jun 15, 2016 5:31 pm

The reason is that there are 'chunk properties', for example:

Code: Select all

the backColor of line 2 of field 1
Without the brackets, tListOfControls is therefore being treated as a potential field reference, hence the "Chunk: error in object expression" error.

The brackets force

Code: Select all

line 2 of tListOfControls
to be evaluated first, and then the whole thing is evaluated as a property of the resulting object, and similarly when it is put into a variable first.

The converse ambiguity can be seen if you have a field

line 1
line 2

which is selected, and executing

Code: Select all

put line 2 of the selectedobject


which will put empty rather than "line 2".

trevix
Posts: 387
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: reference of controls in a variable

Post by trevix » Thu Jun 16, 2016 2:11 pm

Sorry, but I have a hard time to understand.
Please see the attached stack. Is a simple script, to invert the top of two fields, using a var list. The purpose of the script is not important: what I am not sure to understand is how brackets seem to require a different approach along the script.
In one part of the script, this is saved correctly:
...
put item 1 of (line tLineOne of sChoiceList) into tTop
...

In another part of the script, if you take off the comment, trying to save it an error get reported:
...
put tReplacementTop into item 1 of (line tLineOne of sChoiceList)
...

also as error:
...
put tTop into (item 1 of line tLineTwo of sChoiceList)
...
Thanks for clarifying this to me
Attachments
Test3.livecode.zip
(1.57 KiB) Downloaded 55 times
Trevix

trevix
Posts: 387
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: reference of controls in a variable

Post by trevix » Tue Jun 21, 2016 12:19 pm

More on this...

On a script I have the following:

Code: Select all

    repeat with U = 1 to 6  --line 1
        put the abbrev ID of group ("FR_Process" && U) of me into tAbbrID --line 2
        put (item 2 of (the loc of tAbbrID)) & comma & tAbbrID & cr after sChoiceList --line 3
    end repeat
What happens is that on line 3 LiveCode simply stop executing, without reporting an error. Moving brackets around doesn't solve...
This also is not permitted:
put (item 2 of (the loc of tAbbrID of me)) & comma & tAbbrID & cr after sChoiceList
The thing gets fixed only doing this:

Code: Select all

    repeat with U = 1 to 6  --line 1
        put the abbrev ID of group ("FR_Process" && U) of me into tAbbrID --line 2
        put (item 2 of (the loc of group ("FR_Process" && U) of me)) & comma & tAbbrID & cr after sChoiceList --line 3
    end repeat
For what I know, ID should be unique in a stack and LC should know what they are.
I could use the long ID of the group, but the "background" word, from the dictionary, confuse me:
The long ID of a group includes the ID of the current card. If the group does not appear on the current card, requesting its ID causes an execution error. If you need to get the ID of a group, use the "background" terminology instead.
Beside the not reporting of an error, I don't remember to ever have these kind of problems on older versions of LC. It is like if LC scrambles its internal list of things.
Thanks for any help.
Trevix

trevix
Posts: 387
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: reference of controls in a variable

Post by trevix » Wed Jul 13, 2016 4:53 pm

Also, this does not works:

Code: Select all

--button on card 1
on mouseUp
     put the abbrev ID of group "GroupOne" of group "GroupTwo" of  card 2 into tAbbrevID
    put "something" into fld "TextField" of tAbbrevID of group "GroupTwo" of  card 2
end mouseUp
No brackets are allowed on the IDE. How can it be solved?
Trevix
Trevix

trevix
Posts: 387
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: reference of controls in a variable

Post by trevix » Sat Jul 23, 2016 9:30 am

Some one can clarifying me why the above example doesn't work?
Thanks
Trevix

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

Re: reference of controls in a variable

Post by [-hh] » Sat Jul 23, 2016 7:45 pm

An abbrev ID can not be used to build a 'longer' object identification.
Just use the long ID for that. [Or build the string and use "do".]

You could try:

Code: Select all

on mouseUp
    put the abbrev ID of group "GroupOne" of group "GroupTwo" of card 2 into tAbbrevID
    put "something" into fld "TextField" of tAbbrevID -- works if the ID of the group is unique
end mouseUp
But the long ID is of the form: group ID 42 of card ID 13 of stack "myTest.livecode"

As long as you don't use a group that isn't place on any card, this should work:

Code: Select all

on mouseUp
    put the long ID of group "GroupOne" of group "GroupTwo" of card 2 into tLongID
    put "something" into fld "TextField" of tLongID
end mouseUp
shiftLock happens

trevix
Posts: 387
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: reference of controls in a variable

Post by trevix » Mon Jul 25, 2016 11:56 am

Thanks for answering.
I knew of course about long ID, but this wasn't my point.
I wrongly supposed that, once the correct default stack is set and in that stack there is a control with that abbrev ID, being the ID unique, LC would know about it and it's path.
So, this is not true?
Trevix

SparkOut
Posts: 1762
Joined: Sun Sep 23, 2007 4:58 pm

Re: reference of controls in a variable

Post by SparkOut » Mon Jul 25, 2016 1:03 pm

It seems natural to me to expect that a variable can be used to resolve object id/names. I think it's irrelevant whether the id is or isn't unique, if the object reference has been resolved correctly.

There is definitely something wrong in this scenario though.

For instance:

Code: Select all

--button on card 1
on mouseUp
   put the long ID of group "GroupOne" of group "GroupTwo" of  card 2 into tLongID
   put the abbrev ID of group "GroupOne" of group "GroupTwo" of  card 2 into tAbbrevID
   put the short ID of group "GroupOne" of group "GroupTwo" of  card 2 into tShortID
   put "something long" into fld "LongField" of tLongID -- works
   put "something short" into fld "ShortField" of group id tshortID of group "GroupTwo" of  card 2 -- works
   put "something abbrev" into fld "AbbrevField" of tAbbrevID of group "GroupTwo" of  card 2 -- fails with execution error (Chunk: can't find background)
end mouseUp

--button on card 2
on mouseUp
   put the long ID of group "GroupOne" of group "GroupTwo" of  card 2 into tLongID
   put the abbrev ID of group "GroupOne" of group "GroupTwo" of  card 2 into tAbbrevID
   put the short ID of group "GroupOne" of group "GroupTwo" of  card 2 into tShortID
   put "something long" into fld "LongField" of tLongID -- works
   put "something short" into fld "ShortField" of group id tshortID of group "GroupTwo" of  card 2 -- works
   put "something abbrev" into fld "AbbrevField" of tAbbrevID of group "GroupTwo" of  card 2 -- populates the field correctly but then fails with execution error (Chunk: source is not a container)
end mouseUp
It looks like a bug submission is in order

trevix
Posts: 387
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: reference of controls in a variable

Post by trevix » Mon Jul 25, 2016 2:12 pm

Submitted Bug 18080

Thanks SparkOut

Trevix
Trevix

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

Re: reference of controls in a variable

Post by [-hh] » Mon Jul 25, 2016 3:37 pm

Hi all.
what I meant is that this cannot work as long there is a chance for the engine to interpret "tAbbrevID" as variable containing the string "group id 42" of "field id 42".
For "put":
We can use it to build an identifier string and then use "do" but we can't use it as part of an object identifier.
For "set <prop>" or "get <prop>":
Use it as object identifier (but not as 'beginning' part of a longer object identifier).

Code: Select all

on mouseUp
   put the abbrev id of fld 1 into tAbbrevID
   put "abcdefg" into h
   -- put h into tAbbrevID -- puts h into the variable tAbbrevID <----
   do "put h into" && tAbbrevID -- puts correctly h into fld 1
   set text of tAbbrevID to (h&h) -- works
   set backcolor of tAbbrevID to "black" -- works
   put the text of tAbbrevID into fld 2  -- works
end mouseUp
shiftLock happens

trevix
Posts: 387
Joined: Sat Feb 24, 2007 11:25 pm
Location: Italy
Contact:

Re: reference of controls in a variable

Post by trevix » Mon Jul 25, 2016 5:26 pm

I understand that.
But here one more example

Code: Select all

on mouseUp
    put the abbrev ID of group "GroupOne" of group "groupTwo" into tAbbrevID
    put "something abbrev" into fld "AbbrevField" of tAbbrevID  --THIS WORK
    put "something abbrev" into fld "AbbrevField" of tAbbrevID of group "GroupTwo"  --THIS DOESN'T WORK
end mouseUp
Notice that the first time I mistakenly called both groups "groupTwo", I've got an error such:
button "Button": execution error at line 2652 (Handler: can't find handler) near "moveStack", char 1 --(!?)
Trevix

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

Re: reference of controls in a variable

Post by [-hh] » Mon Jul 25, 2016 6:23 pm

Hi trevix,
I see your problem. I had also similar problems in situations that were not this 'deep' (obj of group of group) as yours. I try to understand it this way.
  • The engine interprets the first word of the content of a variable after "of" as object type, if the variable is the end of descriptor:
    ' .. of tAbbrevID' works.
  • The engine doesn't accept a variable after "of" that is followed by other object descriptions, it expects then an object type:
    '.. of tAbbrevID of group "GroupTwo" ' doesn't work.
    This may have reasons in that such a "resolving" parsing could lead to a too deep (if not endless?) parsing loop.
p.s. The error reporting you denote is of course worth a "funny" bug report :-)
shiftLock happens

Post Reply

Return to “Bug Triage”