IT variable becomes Local

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
Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 257
Joined: Mon Jun 10, 2013 1:32 pm

IT variable becomes Local

Post by Lagi Pittas » Wed Jan 17, 2018 3:23 pm

Hi

This might not sound like much of a problem but it's an itch that I need to scratch and it has happened a few times over the years.

I always have variable checking set to on in the editor preferences. I never need to explicitly declare the IT variable at the top level as it's presumably a default Application global.

Every so often though, while I am editing a stack with many cards and substacks that work and have worked for ages,the system (6.7.11) decides that IT hasn't been declared. I can exit livecode and restart -but no joy. If I declare "Global IT" at the top of the script or within the handler everything is fine - but why?

Does anyone know a "poke" in the binary stack file (ouch!!) that could save me from having to recreate the stack again with cut and paste?

It's not a deal breaker but like everything out of the ordinary - I want to know why.

lagi

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 961
Joined: Thu Apr 11, 2013 11:27 am

Re: IT variable becomes Local

Post by LCMark » Wed Jan 17, 2018 4:46 pm

@Lagi: The 'it' variable is actually always local to the handler. Prior to 7 (e.g. 6.7.11) the 'it' variable would only be created at the point a command was parsed which required it - therefore if you tried to use 'it' *before* such a command, you'd get that error (assuming Variable Checking is on). From 7 onwards, 'it' is always declared at the start of the handler implicitly to stop precisely this kind of problem.

Lagi Pittas
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 257
Joined: Mon Jun 10, 2013 1:32 pm

Re: IT variable becomes Local

Post by Lagi Pittas » Wed Jan 17, 2018 5:19 pm

Hi Mark,

All is now fine with the world - In this case I couldn't see the wood for the trees.

Basically I had an Answer statement followed by a put to the messagebox for testing - I removed the answer statement and applied - In most cases I would delete both statements.

But as soon as I saw the dreaded red cross I immediately tried to solve the problem. This explains why most times it went away when I "cleaned up the code" getting rid of superfluous put statements.

The declaration at the parse level makes the "problem" obvious now.

Thanks gain Mark - I can sleep at night.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”