|
|
| Line 32: |
Line 32: |
| **** "|c" doesn't have the same problem, but will cause the text after it not to show. | | **** "|c" doesn't have the same problem, but will cause the text after it not to show. |
|
| |
|
| * Variables (not really a "quirk", more like a "need to know"). | | * Variables |
| ** If you declare a local variable inside an IF block, it is only available inside that IF block. | | ** If you declare a local variable inside an code (such as an IF block) block, it is only available inside that code block. |
| *** In Example 1, "Something" will never print. While in Example 2, "Something" does print.
| | ** See [[Lua_Scope]] for a complete description of the implications of Lua's variable scoping. |
| *** See [[Talk:API_and_scripting_quirks#Variables|Talk]] for more details.
| |
| -- Example 1
| |
| local someVar = true;
| |
| if someVar then
| |
| local someOtherVar = true; -- someOtherVar declared inside an IF block.
| |
| end
| |
| Print(tostring(someOtherVar)); -- Prints "nil" because the variable does not exist.
| |
| if someOtherVar then
| |
| Print("Something"); -- This never gets executed.
| |
| end
| |
| | |
| -- Example 2
| |
| local someVar = true;
| |
| local someOtherVar; -- someOtherVar declared before (outside) an IF block.
| |
| if someVar then
| |
| someOtherVar = true;
| |
| end
| |
| if someOtherVar then
| |
| Print("Something"); -- This executes as expected.
| |
| end
| |
|
| |
|
| == Also See == | | == Also See == |