Board Thread:Support Requests - Getting Technical/@comment-23880286-20150719180003/@comment-24473195-20150719205601

Vogel100 wrote: I copied everything to a sandbox wiki I just found (I was wondering if sandbox.wikia.com existed for these kinds of things, and it did, so that's how I found it) so that testing could be done freely without having to worry about script errors. The only thing I've changed in the current version is add local before the write functions.

The coding of w:c:sandbox:Sandbox 1 is the same as the code for w:c:gravityfalls:Tyler, except for the local things. You can edit the code for the module on the sandbox wiki here if you need to.

The error is "Lua error in Module:Appear at line 16: attempt to call global 'writeAll' (a nil value)." by the way. I think the problem is that it's trying to call a global function while it should be calling the local function. That would explain the error message and why local functions don't work. The question is: why? Now I see the problem, local functions are generally used within another function e.g.:

Another problem is that you can't use something that hasn't been defined,e.g.

The only exception is if your function is global, which means that it can be used anywhere anytime. So if you move your writeseason function above p.main you'll see that it'll work.

Generally speaking, you  declare a function as local if you'll only use it within a function or maybe if you'll only use it once and want to free up memory once it is done!

Edit to add:

Either that or use forward declarations as discussed here.

P.S. This is a nice discussion for future reference.