Page 1 of 1

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

Posted: Fri Apr 18, 2014 3:37 am
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? ;-;

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

Posted: Fri Apr 18, 2014 3:38 am
by xFade
** ATTEMPT TO GET LENGTH OF FIELD NOT INDEX DERP xP

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

Posted: Fri Apr 18, 2014 7:39 am
by TheScriptan
I think that

Code: Select all

#self.objects = nil
and that's why it's not working. :D

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

Posted: Fri Apr 18, 2014 9:52 am
by Robin
It looks like you never call MenuScreen:start()

If you need more help, we're gonna need your .love.

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

Posted: Fri Apr 18, 2014 4:52 pm
by xFade
I did call it, and I do not want to set it to nil.

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

Posted: Fri Apr 18, 2014 5:34 pm
by xFade
bump...

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

Posted: Sat Apr 19, 2014 9:58 am
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.

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

Posted: Sat Apr 19, 2014 6:16 pm
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?

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

Posted: Mon Apr 21, 2014 2:09 am
by xFade
I got it, thank you all :D