quad problem?

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
lippo
Prole
Posts: 8
Joined: Sat Oct 18, 2014 2:40 pm

quad problem?

Post by lippo »

hello I just started to use love
have a problem whith tis code

error this

Code: Select all

Error: main.lua:113: attempt to index global 'quads' (a nil value)
stack traceback:
	main.lua:113: in function 'draw'
	[string "boot.lua"]:410: in function <[string "boot.lua"]:373>
	[C]: in function 'xpcall'
main.lua is:

Code: Select all

--animazione sprite

function love.load()
	--carico immagine
	character = love.graphics.newImage("sprite.png")

	--love.graphics.newQuad( x, y, width, height, sw, sh )	
	love.graphics.newQuad(0, 0, 32, 32, 256, 32)--primo quad
	love.graphics.newQuad(32, 0, 32, 32, 256, 32)--secondo quad
	love.graphics.newQuad(64, 0, 32, 32, 256, 32)--terzo quad
	love.graphics.newQuad(96, 0, 32, 32, 256, 32)--quarto quad
	love.graphics.newQuad(128, 0, 32, 32, 256, 32)--quinto quad
	love.graphics.newQuad(160, 0, 32, 32, 256, 32)--sesto quad
	love.graphics.newQuad(192, 0, 32, 32, 256, 32)--settimo quad
	love.graphics.newQuad(224, 0, 32, 32, 256, 32)--ottavo quad

		
	--ciclo per i quad
	for i = 1,8 do
		love.graphics.newQuad( (i-1)*32, 0, 32, 32, 256, 32 )
	end
	
	local Quad = love.graphics.newQuad function love.load()
		character = love.graphics.newImage("sprite.png")
		
		quads = {}
		quads['right'] = {}
		quads['left'] = {}
			
		for j = 1,8 do
			quads['right'][j] = Quad((j-1)*32,0,32,32,256,32)
			
			quads.left[j]:flip(true,false);
			x = true 
			y = false
			
		end
	end
	
	local Quad = love.graphics.newQuad function love.load()
		
		character = {}
		character.player = love.graphics.newImage("sprite.png")
		character.x = 50
		character.y = 50
		direction = "right"
		interation = 1
		max = 8
		idle = true
		timer = 0.1
		quads = {}
		quads['right'] = {}
		quads['left'] = {}
		
		for j = 1,8 do
			quads['right'][j] = Quad ((j-1)*32,0,32,32,256,32);
			quads['left'][j] = Quad ((j-1)*32,0,32,32,256,32);
			
			quads.left[j]:flip(true,false)
			x = true 
			y = false			
		end
	
	end
		
end

function love.update(dt)
	if idle == false then
		timer = timer + dt
		
		if timer > 0.2 then
			timer = 0.1
			iteration = iteration + 1
			
			if love.keyboard.isDown('right') then
				character.x = character.x + 5
			end
		
			if love.keyboard.isDown('left') then
				character.x = character.x - 5
			end

			if iteration > max then
				iteration = 1
			end
		end
	end

end
	
function love.keypressed(key)

	if quads[key] then
		direction = key
		idle = false
	end	
		
end

function love.keyreleased(key)

	if quads[key] and direction == key then
		idle = true
		iteration = 1
		direction = "right"
	end

end

function love.draw()

	love.graphics.drawq(character.player, quads[direction][iteration], character.x, character.y)

end	

I've already seen the similar post but did not understand where the problem lies
i use 0.8.0 version program in linux xubuntu
thanks for your understanding
User avatar
Cucurbitacée
Prole
Posts: 47
Joined: Fri Dec 14, 2012 10:22 am
Location: Frankfurt am Main

Re: quad problem?

Post by Cucurbitacée »

I will not be very helpful, but you should update to the latest version of LÖVE, as you get an error for a function that doesn't exists anymore. You can now use love.graphics.draw instead of love.graphics.drawq.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: quad problem?

Post by Ref »

You make them but you don't store them anywhere.
You need something like:

Code: Select all

quads = {}
quads[1] = love.graphics.newQuad(....
etc.
and then draw each of the quads.
lippo
Prole
Posts: 8
Joined: Sat Oct 18, 2014 2:40 pm

Re: quad problem?

Post by lippo »

Ref wrote:You make them but you don't store them anywhere.
You need something like:

Code: Select all

quads = {}
quads[1] = love.graphics.newQuad(....
etc.
and then draw each of the quads.
thanks for your help try to include your example in my code :awesome:
lippo
Prole
Posts: 8
Joined: Sat Oct 18, 2014 2:40 pm

Re: quad problem?

Post by lippo »

edit have partly resolved with AnAL module
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 52 guests