我是一个没有太多经验的新程序员;作为一个好的noob,很可能你会看到的下一个代码行可能会显示大量的错误或不精确,因此我提前改变了自己。 所以,情况如下: 最近我与一种新的编程语言(显然是新的)是LUA(使用电晕sdk)接口。我接触写简单代码的语言。 现在我试图执行一个程序,它只是显示受重力影响的两个矩形。当我尝试使用CORONA在PC上模拟应用程序时,它没有任何问题;因建它的Android操作系统后,已经安装了它在我的手机上已经运行的结果是以下错误消息:LUA ERROR在Android上运行应用程序
这是错误消息:
“main.lua.35: ERROR:table expected。如果这是一个函数调用,你可能使用'。'而不是“:”“
这是代码:
local physics = require("physics")
physics.start()
local _W = display.contentWidth
local _H = display.contentHeight
local platform = display.newRect(
--x =
_W/2,
--y =
_H/2,
--width =
100,
--height =
100
)
platform.surfaceType = "rectangle"
local myImage = display.newImage("icon.png",_W/2,50)
local iconCollision = {
friction = 0.0, --attrito
bounce = 0.0, --rimbalzo (forse)
isSensor = true --collisione con altri oggetti
}
physics.addBody(platform,"static")
physics.addBody(myImage,"dynamic",iconCollision) --this is line 35
platform.collision = onCollision
local function onGyroscopeDataReceived(event)
local deltaRadians = event.zRotation * event.deltaTime
local deltaDegrees = deltaRadians * (180/math.pi)
end
local function dragImage(event)
local t=event.target
print(event.phase)
if(event.phase == "moved") then
t.x = event.x
t.y = event.y
end
end
local function onCollision(event)
if (event.phase == "began") then
print("toccato")
end
end
if system.hasEventSource("gyroscope") then
Runtime:addEventListener("gyroscope", onGyroscopeDataReceived)
end
Runtime:addEventListener("collision",onCollision)
myImage:addEventListener("touch",dragImage)
我会很感激那些谁会尽力帮助我。
错误消息完全解释它。它表示它期望一个表作为一个函数参数(实际上是第一个参数),它建议用':'替换'.'。这是因为'tab:func(arg1,arg2)'是'tab.func(tab,arg1,arg2)'的快捷方式。该程序自动插入该表作为函数的第一个参数。 – user6245072
尝试调用'物理:addBody(平台,“静态”)和'物理:addBody(myImage,“动态”,iconCollision)'或者甚至'physics.addBody(phisycs,platform,“static”)''和'physics。 addBody(物理,myImage,“动态”,iconCollision)'它应该工作。 – user6245072
'platform.collision = onCollision'行必须在函数'onCollision'的主体后面 –