Lua Modules

Posted by Daved on Wed 07 Apr 2010 12:47 AM — 4 posts, 15,929 views.

#0
So I'm rewriting my system for aetolia, looking at Lusternia's treant system as a guide. I've put up my main script file and a snippet from my affliction tracking script file on lua.pastebin here:


http://lua.pastebin.com/A36csk44

http://lua.pastebin.com/buTiziBm


I'm getting this error from MUSHClient:


Run-time error
World: AMTS
Immediate execution
.\affs.lua:21: attempt to index global 'affs' (a nil value)
stack traceback:
.\affs.lua:21: in main chunk
[C]: in function 'require'
[string "Script file"]:7: in main chunk

Any advice is appreciated.
Australia Forum Administrator #1
I don't see where you are creating the affs table.
#2
There's no aff table, or shouldn't be. Line 21 that the error message references is:

21: function affs:init()
22: afflictions = {}
23: affs:diag()
24: end

It seems to be having a problem with the name of the function, but I'm not terribly sure that's the case since I used the same format that the Treat system in Lusternia uses.
USA #3
Daved said:

There's no aff table, or shouldn't be. Line 21 that the error message references is:

21: function affs:init()
22: afflictions = {}
23: affs:diag()
24: end

It seems to be having a problem with the name of the function, but I'm not terribly sure that's the case since I used the same format that the Treat system in Lusternia uses.


Right, that's the problem. The syntax "function affs:init()" is interpreted by the Lua parser exactly as though it were "affs.init = function(self)". You need to have an "affs" table to put the "init" function into, or this syntax won't work.