Basic Problem : I can’t seem to get metatables to work unless called through main.lua.
So I thoroughly trudged through Beebe’s awesome Tutorial: Modular Classes article and decided it would probably be a good idea. My code is a mess and this might help organize the functions a bit.
However, this code throws an error (“attempt to index a nil value”) unless I call it in main.lua. (Which defeats the entire point of the object since I’d have to make it global for use anywhere else.)
The called code (say, from another lua file like “somewhere.lua”)
local shop = require ("shop")
local shop1 = shop.new() -- throws an error
The shop.lua file:
[code]local shop = {}
local shop_mt = { __index = shop }
function shop.new()
local newShop = { level=1, name=“Temp” }
return setmetatable(newShop, shop_mt)
end
return shop[/code]
50/50 that I’ve just made some sort of obvious mistake…? [import]uid: 41884 topic_id: 22915 reply_id: 322915[/import]
