电晕:错误加载模块错误
Corona: Error Loading Module Error
我正在使用元表在 Corona SDK 中创建一个 OOP 游戏,我的代码遇到了一些问题。
这是我的 main.lua 文件:
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
local hero = require("hero")
local environment = require("environment")
local obstacle = require("obstacle")
local player = hero.new("Billy", 0, 10)
这是我的 hero.lua class 文件:
local hero = {}
local hero_mt = {_index = hero}
--Constructor
function hero.new (name, positionX, positionY)
local newHero = {
name = name
positionX = positionX or 0
positionY = positionY or 0
}
return setmetatable( newHero, herp_mt )
function hero:Jump(amount)
end
我收到的错误如下:
从文件 'hero.lua' 加载模块 'hero' 时出错:
hero.lua:14 '}' expected (to close '{' at line 12) near
'positionX'
我遵循了该站点使用的相同语法 (https://coronalabs.com/blog/2011/09/29/tutorial-modular-classes-in-corona/)
但仍然没有任何效果。有什么想法吗?
您在声明新英雄时缺少逗号 table。所有 table 的属性都必须用逗号分隔。有关详细信息,请参阅 documentation。最后一个元素也可以有逗号。
local newHero = {
name = name,
positionX = positionX or 0,
positionY = positionY or 0,
}
您还缺少函数 hero.new()
的结尾 end
并且需要 return 英雄 table 在英雄文件的末尾,就像这样: return hero
这样你就可以在主文件中实际调用 hero.new()
。
我正在使用元表在 Corona SDK 中创建一个 OOP 游戏,我的代码遇到了一些问题。
这是我的 main.lua 文件:
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
local hero = require("hero")
local environment = require("environment")
local obstacle = require("obstacle")
local player = hero.new("Billy", 0, 10)
这是我的 hero.lua class 文件:
local hero = {}
local hero_mt = {_index = hero}
--Constructor
function hero.new (name, positionX, positionY)
local newHero = {
name = name
positionX = positionX or 0
positionY = positionY or 0
}
return setmetatable( newHero, herp_mt )
function hero:Jump(amount)
end
我收到的错误如下:
从文件 'hero.lua' 加载模块 'hero' 时出错: hero.lua:14 '}' expected (to close '{' at line 12) near 'positionX'
我遵循了该站点使用的相同语法 (https://coronalabs.com/blog/2011/09/29/tutorial-modular-classes-in-corona/) 但仍然没有任何效果。有什么想法吗?
您在声明新英雄时缺少逗号 table。所有 table 的属性都必须用逗号分隔。有关详细信息,请参阅 documentation。最后一个元素也可以有逗号。
local newHero = {
name = name,
positionX = positionX or 0,
positionY = positionY or 0,
}
您还缺少函数 hero.new()
的结尾 end
并且需要 return 英雄 table 在英雄文件的末尾,就像这样: return hero
这样你就可以在主文件中实际调用 hero.new()
。