Page 1 of 1

Error?

Posted: Sun Jul 27, 2014 4:57 pm
by Wrathguy78
My window says main.lua:11: attempt to index global 'ents' (a nil value)

my code is:

Code: Select all


function love.load()
    require ("entities")
	ents.Startup()
	love.graphics.setBackgroundColor( 255, 255, 255 )
	xCloud = 0 
	imageCloud = love.graphics.newImage("textures/cloud.png") 
end	
	for i = 1, 8 do
		ents.Create( "moon", -math.random(128, 256), 128 )
	end
	
function love.draw()
    local x = love.mouse.getX( )
	local y = love.mouse.getY( )
	
	love.graphics.setColor( 153, 217, 234, 255 )
	love.graphics.rectangle( "fill", 0, 0, 800, 300 )
	 
	
	love.graphics.setColor( 255, 255, 255, 255 )
	love.graphics.draw( imageCloud, xCloud - 256, 128, 0, 1, 1, 0, 0 )
	
	love.graphics.setColor( 103, 164, 21, 255 )
	love.graphics.rectangle( "fill", 0, 300, 800, 300 )
	
    ents:draw()	
end

function love.update(dt)
    xCloud = xCloud + 32*dt
	if xCloud >= (800 + 256) then
	    xCloud = 0     
    end
	ent:update(dt)
end

function love.focus(bool)
end

function love.keypressed( key, unicode )
        print ("You just pressed " .. key)
end

function love.keyreleased( key, unicode )
        print ("You just released " .. key)
end

function love.mousepressed( x, y, button )
end

function love.mousereleased( x, y, button )
end

function love.quit()
end

Re: Error?

Posted: Sun Jul 27, 2014 7:31 pm
by micha
The problem lies in the beginning of the code:

Code: Select all

function love.load()
    require ("entities")
   ents.Startup()
   love.graphics.setBackgroundColor( 255, 255, 255 )
   xCloud = 0
   imageCloud = love.graphics.newImage("textures/cloud.png")
end   
   for i = 1, 8 do
      ents.Create( "moon", -math.random(128, 256), 128 )
   end
With the first end, the love.load function ends. The for-loop after that is not inside any function. Because of that, this loop is run beofre the love.load function is run. At this point in time, the entities-module is not yet required.

Re: Error?

Posted: Sun Jul 27, 2014 7:48 pm
by Wrathguy78
When i remoe the end it says main.lua :57: 'end' expected (to close 'function' at line 3) near '<eof>

Re: Error?

Posted: Sun Jul 27, 2014 7:50 pm
by micha
The number of "end"s is correct, but the position is incorrect. Move the first "end" behind the "end" of the for loop.

Re: Error?

Posted: Sun Jul 27, 2014 8:19 pm
by dusoft
[quote="micha"]The problem lies in the beginning of the code:

Code: Select all

function love.load()
    require ("entities")
or move require statement into global namespace (out of the function)