How to get editor to indent on "do 'repeat'..."?

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

Post Reply
MichaelBluejay
Posts: 155
Joined: Thu Jul 01, 2010 11:50 am

How to get editor to indent on "do 'repeat'..."?

Post by MichaelBluejay » Wed Oct 09, 2019 2:08 pm

Code editor doesn't indent the "repeat" if it's executed via a "do":

Code: Select all

put fld manyLines1 into tDebits
put fld manyLines2 into tCredits

repeat for each item debitOrCredit in "tDebits,tCredits"
   do "repeat for each line theLine in" && debitOrCredit
   addToDatabase(item 2 of theLine, item 5 of theLine) -- not indented
   do "end repeat"
end repeat
I presume there's no way to get the code editor to indent properly in this case? If not, then maybe there's a better way to process this data without "do 'repeat...". I'm open to that, I'm not married to "do 'repeat..."

One thing I could do would be to tag each line of each field with some identifier, then combine text of both fields, and then operate on them as a single string. That feels clumsy, though.
Last edited by MichaelBluejay on Wed Oct 09, 2019 2:45 pm, edited 1 time in total.

bogs
Posts: 3912
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to get editor to indent on "do 'repeat'..."?

Post by bogs » Wed Oct 09, 2019 2:22 pm

Ok, I'll bite.

Why use the "do" instead of just nesting the repeats? (not in the IDE at the moment, just an honest question)

Code: Select all

put fld manyLines1 into tDebits
put fld manyLines2 into tCredits

repeat for each item debitOrCredit in "tDebits,tCredits"
   repeat for each line theLine in theItem
      addToDatabase(item 2 of theLine, item 5 of theLine) -- now indented
   end repeat
end repeat
Image

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

Re: How to get editor to indent on "do 'repeat'..."?

Post by dunbarx » Wed Oct 09, 2019 2:35 pm

Michael.

You really must start placing literals in quotes. Trust me. You will be glad you did.

Code: Select all

put fld "manyLines1" into tDebits
There is a preference that sets the SE indent level, from 2 to 5 chars. But it does not go to 0. What I mean is, I have never seen the SE fail to indent. You might try playing with that preference just to see if something changes.

What OS?

Craig

MichaelBluejay
Posts: 155
Joined: Thu Jul 01, 2010 11:50 am

Re: How to get editor to indent on "do 'repeat'..."?

Post by MichaelBluejay » Wed Oct 09, 2019 2:52 pm

bogs, I'm afraid that doesn't work because "theLine" doesn't refer to each line in the variable tDebits, it refers to the number of lines in the *string literal* "tDebits". Try this:

Code: Select all

put (a,b,c,d,e,f,g) into tDebits
put (a,b,c,d,e,f,g) into tCredits
replace comma with cr in tDebits
replace comma with cr in tCredits
answer tDebits -- a bunch of lines

repeat for each item debitOrCredit in "tDebits,tCredits"
   repeat for each line theLine in debitOrCredit
      answer theLine -- not a line of data!
   end repeat
end repeat
dunbarx, it's Mac OS X. The thing is, once I put the "repeat" inside a "do", the code editor doesn't see the command as "repeat", it sees it as "do", so it doesn't indent. In fact, if you do that, then you have to put the "end repeat" inside a "do" otherwise you get an error.

I'm rethinking my data structure so I don't have to have multiple repeats. The hardest part of this project isn't the coding (LiveCode syntax is pretty damn easy), it's figuring out how to organize the data.

bogs
Posts: 3912
Joined: Sat Feb 25, 2017 10:45 pm

Re: How to get editor to indent on "do 'repeat'..."?

Post by bogs » Wed Oct 09, 2019 3:02 pm

Once I thought about it, I figured out you were trying to get the line to either execute or return a result as if the line were code, however, it doesn't change the structure of what I was thinking, instead, you just move the do to this kind of format (I think) -
...my code from earlier, using do still in a nested repeat structure:

Code: Select all

put fld manyLines1 into tDebits
put fld manyLines2 into tCredits

repeat for each item debitOrCredit in "tDebits,tCredits"
   repeat with x=1 to the number of lines of theItem
      do line x of theItem && {the rest of your code} -- still indented
   end repeat
end repeat

Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”