get line x of item y fails

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
pderks
Posts: 58
Joined: Sat May 14, 2011 4:25 pm
Location: Krefeld • Deutschland

get line x of item y fails

Post by pderks » Fri May 08, 2015 10:58 am

Dictionary says: "A single item can contain multiple characters, multiple words, and multiple lines."

Code: Select all

put "a,b" & cr & "c,d,e" into DataX
put DataX & cr & cr into msg
put item 2 of DataX into ItemX
put ItemX & cr & cr after msg
put line 2 of ItemX & cr & cr after msg
but :

Code: Select all

put line 2 of item 2 of DataX after msg
results in:
"Script compile error: Error description: Chunk: bad chunk order (must be small to large)"

Peter

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am
Location: Bordeaux, France

Re: get line x of item y fails

Post by Dixie » Fri May 08, 2015 1:08 pm

nearly there...:-)

Code: Select all

put item 2 of line 2 of DataX after msg

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

Re: get line x of item y fails

Post by dunbarx » Fri May 08, 2015 3:28 pm

Hi.

Unlike with HC, the LC parser will not allow you to extract a "larger" chunk from a "smaller" one. The order must be hierarchal, char, word, item, line, container. In one way this makes sense; how could you ask for the third line of the second character? HC would have returned empty with such a request. LC throws an error.

But HC would allow you to extract the second item from the second word ("aa bb,cc,dd ee" would give "cc"). So this flexibility may in fact make sense in many cases, but is still proscribed in LC. It surely derives from a more rigorous parser, in the interest of robustness and speed.

Craig Newman

pderks
Posts: 58
Joined: Sat May 14, 2011 4:25 pm
Location: Krefeld • Deutschland

Re: get line x of item y fails

Post by pderks » Sat May 09, 2015 1:50 am

Hi Craig,

cordial thanks for your profound & exhausting answer to an old HyperCardist | HyperCardian.

Peter

Fermin
Posts: 142
Joined: Fri Jun 05, 2015 10:44 pm

Re: get line x of item y fails

Post by Fermin » Thu Apr 15, 2021 12:48 pm

I think that using parenthesis can do the trick...

Code: Select all

put line 2 of (item 2 of DataX) after msg

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

Re: get line x of item y fails

Post by dunbarx » Thu Apr 15, 2021 2:52 pm

Fermin.

Correct, that is the standard way out of that restriction. The engine resolves the contents of the parens, and all is then well.

Craig

Post Reply

Return to “Talking LiveCode”