CoronaSDK导演错误
2015-3-11 9:4:35
收藏:0
阅读:213
评论:1
我目前正在使用CoronaSDK和Lua编写跨平台应用程序。我正在使用导演包来更改场景。但是,我得到了以下错误:
“Director ERROR: Failed to execute new(params) function on 'startUp'。”
我知道错误来自我的主类。这是:
-----------------------------------------------------------------------------------------
-
- main.lua
-
-----------------------------------------------------------------------------------------
local director = require(“director”)
local mainGroup = display.newGroup()
splash = display.newImage(“images / logo.png”)
local main = function()
splash:removeSelf()
splash = nil
mainGroup:insert(director.directorView)
local widget = require “widget”
--显示默认状态栏(iOS)
display.setStatusBar(display.DefaultStatusBar)
local mainGroup = display.newGroup()
--选项卡按钮事件侦听器:
local function onFirstView(event)
director:changeScene(“startUp”)
end
local function onSecondView(event)
director:changeScene(“home”)
end
--表格设置按钮
local tabButtons = {
{label =“主页”,up =“icon1.png”,down =“icon1-down.png”,width = 32,height = 32,onPress = onFirstView,selected = true},
{label =“卡片”,up =“icon2.png”,down =“icon2-down.png”,width = 32,height = 32,onPress = onSecondView},
}
--创建实际的tabBar widget
local tabBar = widget.newTabBar {
top = display.contentHeight,
buttons = tabButtons
}
--我认为是这行导致了错误
director:changeScene(“startUp”)
return true
end
timer.performWithDelay(3000,main,1)
这是我的startUp.lua文件:
模块(...,package.seeall)
function new()
require“sqlite3”
local director = require(“director”)
-连接到数据库或创建它。
-每个用户都有自己的数据库 * ***
local path = system.pathForFile(“data.db”,system.DocumentsDirectory)
local db = sqlite3.open(path)
-如果数据库表不存在,则创建它
local tablesetup = [[CREATE TABLE IF NOT EXISTS User(id Integer autoincrement PRIMARY KEY,firstname,lastname); ]]
db:exec(tablesetup)
for row in db:nrows(“SELECT * FROM User”)do
-如果用户在数据库中,则转到主页。
director.changeScene(“home”)
end
-如果不在数据库中,请转到表格
director.changeScene(“forms”)
-捕捉应用程序退出
Runtime:addEventListener(“system”,onSystemEvent)
-处理应用程序退出-关闭数据库连接
local function onSystemEvent(event)
if(event.type ==“applicationExit”)then
db:close()
end
print(“数据库已关闭”)
end
end
这是我在控制台中收到的错误:
运行时错误director.lua:1092:尝试调用方法'insert'(nil值)
堆栈跟踪:在函数'insert'中在函数'changeScene'
---------------
导演错误:未能在“startUp”上执行新的(params)函数。
---------------
断言失败
---------------
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
错误是关于导演类的错误。它发生是因为你的 startUp.lua 中有一些错误。
你是否使用了最新的导演类(1.4版本)?最新的导演类会显示实际的错误信息。
另外,注意到文件名区分大小写。你的文件必须是 startUp.lua 而不是startup.lua。
编辑:
我可以想到两件事。
1.尝试在 startUp.lua 的两个位置将 director.changeScene 改为 director:changeScene。
2.尝试在 main.lua 中删除第二个 local mainGroup = display.newGroup() (尽管我觉得这可能不是问题)
实际错误信息
----------------------- Director ERROR: Failed to execute new( params ) function on 'wifiscreen'. ----------------------- e:\corona\satheesh\doodle2\wifiscreen.lua:231: attempt to index global 'x' (a nil value) -----------------------第二行是实际的错误信息。
我认为发现了错误
我认为错误是因为你没有一个 onSystemEvent 函数。通常,如果尝试向不存在的函数添加监听器,就会出现 assertion failed 错误!