lua - Modular Classes with Corona SDK -
i'm trying create class spawn new objects on screen. i'm following this tutorial
my goal link this:
local box = box.new( "first", 0, 62 ) -- spawn box on screen on x = 0, y = 62 this class:
box.lua local box = {} local box_mt = {__index = box } -- metatable function box.new (nome, x, y) local newbox = { local nome = display.newimagerect( "images/box.png", 210, 70 ) newbox.x = x newbox.y = y } return setmetatable( newbox, box_mt ) } end so far doing require ("box") on level1.lua game crashing
this error failed parse error message: error loading module 'level1' file '/users/mc309bza/desktop/corona/platform/level1.lua': /users/mc309bza/desktop/corona/platform/level1.lua:28: syntax error near 'function' any ideas? thanks!
the closing bracket of table @ wrong place. use:
local newbox = {} local nome = display.newimagerect( "images/box.png", 210, 70 ) newbox.x = x newbox.y = y don't forget remove close } have after newbox. however, if intent make creation of boxes automated, should use function instead, since display.newimagerect class. use function:
function mynewbox(x, y) local nome = display.newimagerect( "images/box.png", 210, 70 ) nome.x = x nome.y = y ... other nome settings ... return nome end
Comments
Post a Comment