gpt4 book ai didi

lua - Corona SDK(LUA) - 尝试调用 upvalue 'spawnEnemy'(零值)

转载 作者:行者123 更新时间:2023-12-02 21:53:26 26 4
gpt4 key购买 nike

我只是想将 eventListener 添加到一个对象,当我点击它时它应该消失。但我收到标题中提到的错误。这是我此时的完整代码:

-- housekeeping stuff

display.setStatusBar(display.HiddenStatusBar)

local centerX = display.contentCenterX
local centerY = display.contentCenterY

-- set up forward references

local spawnEnemy

-- preload audio

-- create play screens

local function createPlayScreen()

local bg = display.newImage("background.png")
bg.y = 130
bg.x = 100
bg.alpha = 0

local planet = display.newImage("planet.png")
planet.x = centerX
planet.y = display.contentHeight +60
planet.alpha = 0

transition.to( bg, { time = 2000, alpha = 1, y = centerY, x = centerX } )

local function showTitle()
local gametitle = display.newImage("gametitle.png")
gametitle.alpha = 0
gametitle:scale (4, 4)
transition.to( gametitle, { time = 500, alpha = 1, xScale = 1, yScale = 1 })
spawnEnemy()
end
transition.to( planet, { time = 2000, alpha = 1, y = centerY, onComplete = showTitle } )
end

-- game functions

local function shipSmash(event)

local obj = event.target
display.remove( obj )

end

local function spawnEnemy()

local enemy = display.newImage("beetleship.png")
enemy.x = math.random(20, display.contentWidth - 20)
enemy.y = math.random(20, display.contentHeight - 20)
enemy:addEventListener ( "tap", shipSmash )

end


local function startGame()

end


local function planetDamage()

end


local function hitPlanet(obj)

end




createPlayScreen()
startGame()

这是错误窗口的样子:

enter image description here

我在这个领域有点新(LUA编程),所以很抱歉可能是愚蠢的语法错误或其他什么,但我看到的是,在我编写这行代码后,这个错误出现了: enemy:addEventListener ( “点击”,shipSmash)

最佳答案

本地函数spawnEnemy()更改为函数spawnEnemy(),因为该变量之前已声明。是的,这是初学者典型的 Lua 陷阱。

关于lua - Corona SDK(LUA) - 尝试调用 upvalue 'spawnEnemy'(零值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18164927/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com