cre8eve
cre8eve

Reputation: 381

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. Please help :)

Upvotes: 0

Views: 201

Answers (1)

Paul Kulchenko
Paul Kulchenko

Reputation: 26744

This error appears to be a generic message when there is a run-time error during the execution of Corona events. I found several references to the same issue (for example, 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. You original code probably "works" because it doesn't get into that section (your day.hour == 1 condition returns "false" most of the time).

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. It's possible that you assign a value to it that breaks something in other parts of your program.

Upvotes: 1

Related Questions