Lua 参数的值为零
我正在创造一个游戏,在其中液体会出来。我使用的是电晕物理引擎的粒子系统。对于粒子群的参数,我通过一种方法得到。当我运行程序时,我得到一条错误消息,说参数是一个nil值 代码:Lua 参数的值为零,lua,coronasdk,Lua,Coronasdk,我正在创造一个游戏,在其中液体会出来。我使用的是电晕物理引擎的粒子系统。对于粒子群的参数,我通过一种方法得到。当我运行程序时,我得到一条错误消息,说参数是一个nil值 代码: -- Will randomly drop water stream at random locations and with random colors --Delcare class variables local physics = (require"physics") physics.start() loc
-- Will randomly drop water stream at random locations and with random colors
--Delcare class variables
local physics = (require"physics")
physics.start()
local w = display.contentWidth
local h = display.contentHeight
local particleSystem = physics.newParticleSystem({
filename = "particle.png",
colorMixingStrength = 0.1,
radius = 3,
imageRadius = 6
})
--function to start the water stream
local function start()
end
--fucntion to end the water stream
local function stop()
end
--a function to create particle paramerters
-- flag to determine if the particle parameter should have random colors
-- WILL have RANDOM location
local function createParticleParameter(flag, x, y, color)
local param = {
flags = flags,
x = x,
y = y,
color = color,
radius = 10,
linearVelocityX = 0,
linearVelocityY = 10,
lifetime = 10
}
return param
end
local function onTimer()
local parmas = createParticleParameter("water", math.random(0, display.contentWidth), 0, {0, 1, 0})
particleSystem:createGroup(params)
end
timer.performWithDelay( 1000, onTimer, 0 )
错误消息:
---------------------------
Corona Runtime Error
---------------------------
attempt to index a nil value
stack traceback:
[C]: in function 'createGroup'
main.lua:47: in function '_listener'
?: in function <?:167>
?: in function <?:221>
唯一的主要区别是我手动放置了参数。
为什么会这样 你把params拼错了
local parmas = createParticleParameter("water", math.random(0, display.contentWidth), 0, {0, 1, 0})
具有讽刺意味的是,问题的标题“parameter”拼写错误。发布的代码注释中有几个拼写错误,包括“参数”和“功能”。因此,从上下文来看,拼写错误的变量名并不令人震惊。我真的很抱歉,我从来没有想到我拼写错了什么。我很抱歉浪费了你的时间,我会尽力不做这样愚蠢的事情
local parmas = createParticleParameter("water", math.random(0, display.contentWidth), 0, {0, 1, 0})