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
IT variable becomes Local
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
Re: IT variable becomes Local
@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.
-
- VIP Livecode Opensource Backer
- Posts: 365
- Joined: Mon Jun 10, 2013 1:32 pm
Re: IT variable becomes Local
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.
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.