attempt to index field '?' (a nil value)

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

attempt to index field '?' (a nil value)

Post by xFade »

Code: Select all

MenuScreen = {}

r = 255
b = 255
g = 255

ly = -120
t = 0

function wait(seconds)
	while seconds > 0 do
		seconds = seconds - coroutine.yield(true)
	end
end

function MenuScreen:start()
	self.objects = {}
	self.co = coroutine.wrap(function()
		ly = -120
		wait(1)
		self.objects[1] = love.graphics.newImage(idir.."gametitle.png")
		repeat
			wait(.01)
			t = t + 5
			ly = ly + 5
		until ly >= 120
		wait(0.5)
	end)
end

function MenuScreen:update(dt)
	self.co(dt)
end

function MenuScreen:draw()
	for i = 1, #self.objects do -- Error is here according to the console...
		love.graphics.setColor(r,g,b,t)
		love.graphics.draw(self.objects[i],0,ly)
    end
end
So I randomly started to get this error. Any help? ;-;
(ง'̀-'́)ง
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

Re: attempt to index field '?' (a nil value)

Post by xFade »

** ATTEMPT TO GET LENGTH OF FIELD NOT INDEX DERP xP
(ง'̀-'́)ง
TheScriptan
Citizen
Posts: 56
Joined: Wed Feb 27, 2013 7:53 pm

Re: attempt to index field '?' (a nil value)

Post by TheScriptan »

I think that

Code: Select all

#self.objects = nil
and that's why it's not working. :D
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: attempt to index field '?' (a nil value)

Post by Robin »

It looks like you never call MenuScreen:start()

If you need more help, we're gonna need your .love.
Help us help you: attach a .love.
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

Re: attempt to index field '?' (a nil value)

Post by xFade »

I did call it, and I do not want to set it to nil.
(ง'̀-'́)ง
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

Re: attempt to index field '?' (a nil value)

Post by xFade »

bump...
(ง'̀-'́)ง
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: attempt to index field '?' (a nil value)

Post by Robin »

That's way too soon to bump.

You only check for ready once, when it's false. Solution: remove every mention of that awful piece of global state ready and call MenuScreen:start() instead of setting it to true.
Help us help you: attach a .love.
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

Re: attempt to index field '?' (a nil value)

Post by xFade »

I apologize I was just very eager to fix the issue. I did what you told me to do and now I get a new error :T

Error:
MenuScreen.lua:33: cannot resume dead coroutine. Is there another method to make the Game's title slide in without coroutines?
(ง'̀-'́)ง
User avatar
xFade
Prole
Posts: 41
Joined: Mon Dec 23, 2013 6:04 pm

Re: attempt to index field '?' (a nil value)

Post by xFade »

I got it, thank you all :D
(ง'̀-'́)ง
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests