简体   繁体   English

在Lua,Corona SDK中定义函数时出错

[英]Error when defining a function in lua, corona sdk

Please, help me figure out what is the problem in the code. 请帮我找出代码中的问题。 I am defining a function 我正在定义一个功能

local function goOnLesson()
   if date.hour==1  then
   index=1
   local subj=schToday[index]
   local text = display.newRetinaText("А сейчас у тебя: "..subj, 0, 0, native.systemFont, 70)
   text:setTextColor(128,64,0)
   text:setReferencePoint(display.CenterReferencePoint)
   localGroup:insert(text)
   end
end

And when I'm running it, everything is fine. 当我运行它时,一切都很好。

I reorganized the code and I don't need if block anymore 我重新组织了代码,不再需要阻塞了

local function goOnLesson()
   index=1
   local subj=schToday[index]
   local text = display.newRetinaText("А сейчас у тебя: "..subj, 0, 0, native.systemFont, 70)
   text:setTextColor(128,64,0)
   text:setReferencePoint(display.CenterReferencePoint)
   localGroup:insert(text)
end

I just removed if-end block but now it doesn't work. 我刚刚删除了if-end块,但现在不起作用。 Please help :) 请帮忙 :)

This error appears to be a generic message when there is a run-time error during the execution of Corona events. 当在执行Corona事件的过程中出现运行时错误时,此错误似乎是一条通用消息。 I found several references to the same issue (for example, here ). 我找到了几个引用同一问题的参考(例如, here )。

It's possible that schToday doesn't have any elements, and your subj variable gets a nil value, which then fails on string concatenation. schToday可能没有任何元素,并且您的subj变量获得了一个nil值,然后在字符串连接时失败。 You original code probably "works" because it doesn't get into that section (your day.hour == 1 condition returns "false" most of the time). 您的原始代码可能“有效”,因为它没有进入该部分(您的day.hour == 1条件day.hour == 1返回“ false”)。

I suggest you doublecheck your code to make sure it works as you expect it to work. 我建议您仔细检查代码,以确保它能按预期工作。

Another thing to try is to localize your index variable. 另一件事是本地化index变量。 It's possible that you assign a value to it that breaks something in other parts of your program. 您可能会给它分配一个值,该值会破坏程序其他部分的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM