Strict compilation mode

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

Post Reply
anmldr
Posts: 459
Joined: Tue Sep 11, 2012 11:13 pm

Strict compilation mode

Post by anmldr » Mon Aug 17, 2020 11:12 pm

Code: Select all

on mouseUp
  // local tAdd
   put 1 into tAdd
   repeat with x = 1 to 10
      add 1 to tAdd
   end repeat
end mouseUp
This is just an example. If I have strict compilation mode selected in Preferences then there is an error noted at "put 1 into tAdd". That is expected. If I remove the "//" then it is declared and no error. This is also expected behavior.

However, WHY is there never an error on the "repeat with x = 1 to 10" line? Isn't "x" a local variable also in the script above? Why does it not need to be declared?

Linda

AlbertAA
Posts: 41
Joined: Thu May 28, 2020 1:42 pm

Re: Strict compilation mode

Post by AlbertAA » Tue Aug 18, 2020 3:28 am

Not having to declare local variables explicitly is one of the many features/bugs or strengths/weaknesses of LiveCode.
I advise to remove the "//" (which caused all your problems), and also to remove the "local tAdd" (which you do not need).
Best luck

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

Re: Strict compilation mode

Post by dunbarx » Tue Aug 18, 2020 3:31 am

Hi.

"x' is indeed "declared" by virtue of creating the "repeat with" control structure. It is just how LC works. It is a good thing.

Craig
Last edited by dunbarx on Tue Aug 18, 2020 2:15 pm, edited 1 time in total.

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

Re: Strict compilation mode

Post by dunbarx » Tue Aug 18, 2020 3:35 am

Albert.
Not having to declare local variables explicitly is one of the many features/bugs or strengths/weaknesses of LiveCode.
Yes, but in strict compilation mode LC becomes a bit more like other languages, in that declarations must be explicitly made prior to using a variable in any way. LC will throw and error if you do not. I never use it. Old fashioned, you know.

Craig

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

Re: Strict compilation mode

Post by bogs » Tue Aug 18, 2020 10:52 am

anmldr wrote:
Mon Aug 17, 2020 11:12 pm
However, WHY is there never an error on the "repeat with x = 1 to 10" line? Isn't "x" a local variable also in the script above? Why does it not need to be declared?
Not exactly. Repeat is a control structure, and the conditions are predefined already by the structure.
Dictionary -
The condition is any expression that evaluates to true or false.
The number, startValue, endValue, and increment are numbers or expressions that evaluate to numbers.
The counter or labelVariable is a legal variable name.
The chunkType is one of character (or char), word, line, item, or token.
The container is any existing container. The array is any existing container that contains an array of values.
The statementList consists of one or more LiveCode statements, and can also include if, switch, try, or repeat control structures.


The with form:
The with counter = startValue to endValue form and the with counter = startValue down to endValue form set the counter to the startValue at the beginning of the loop, and increase (or decrease, if you're using the down to form) the countVariable by 1 each time through the loop. When the counter is greater than or equal to the endValue, (less than or equal to, if you're using the down to form), the loop performs its final iteration and then ends.
in the case of a repeat loop, x is not a variable being declared/initiated by you.
Image

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”