Error?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Wrathguy78
Prole
Posts: 10
Joined: Sun Jul 27, 2014 4:54 pm

Error?

Post 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
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Error?

Post 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.
Wrathguy78
Prole
Posts: 10
Joined: Sun Jul 27, 2014 4:54 pm

Re: Error?

Post by Wrathguy78 »

When i remoe the end it says main.lua :57: 'end' expected (to close 'function' at line 3) near '<eof>
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Error?

Post 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.
User avatar
dusoft
Party member
Posts: 497
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Error?

Post 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)
Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests