Page 1 of 1

Problems with quads

Posted: Thu Sep 19, 2013 10:05 pm
by duiliomelhor
I am wanting to do an animation with quads, made ​​the code more is showing an error when executing, I am not able to see the problems, like if someone would like me ajudar.segue the image of the error and the code.
Image


Code: Select all

require("Naruto")
require("Sasuke")
require("Kyubi")
require("Konoha")
local Quad = love.graphics.newQuad
function love.load()

--Carregar sprites naruto
Naruto_correndo = love.graphics.newImage(Naruto["Naruto_correndo"])




   --Animação do naruto
Naruto_correndo_quads = {

		a = {
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
		};
		d = {
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
		};

	}
	iterator = 1
	max = 4
	timer = 0
	moving = false
	direction = "down"





--Carregar sprites Sasuke
corrida1_sasuke =love.graphics.newImage(Sasuke["sprites"])

--Carregar sprites Kyubi
invocacao_kyube =love.graphics.newImage(Kyubi["sprite"])

--Carregar imagem de fundo
imagem_fundo =love.graphics.newImage(Konoha["sprite"])

--Carregar som de fundo

musica_fundo = love.audio.newSource("sounds/musica_tema.mp3")
love.audio.play(musica_fundo)


end






function love.update(dt)


-- Movimento do Naruto


if moving then
		timer = timer + dt
		if timer > 0.2 then
			timer = 0
			iterator = iterator + 1
			if iterator > max then
				iterator = 1
			end
		end
	end
end

function love.draw()

--Mostrar imagem de fundo

   love.graphics.draw(imagem_fundo,Konoha.cordx,Konoha.cordy)


   love.graphics.print("Naruto vs Sasuke",285,300,0,2,2)




--Mostrar imagem Sasuke

   love.graphics.draw(corrida1_sasuke,Sasuke.cordx,Sasuke.cordy)


   -- Oyabin invocação
   if love.keyboard.isDown('i') then
      love.graphics.print("kushiose no jutsu",100,100)
	  love.graphics.draw(invocacao_kyube,Kyubi.cordx,Kyubi.cordy)
end




  --Animação do naruto ---------------------------------------

	love.graphics.drawq(Naruto_correndo, Naruto_correndo_quads[direction][iterator], 5, 5)

end

----------------------------------------
function love.keypressed(key)
	if Naruto_correndo_quads[key] then
		moving = true
		direction = key
	end
end
function love.keyreleased(key)
	if quads[key] and direction == key then
		moving = false
		direction = "down"
		iterator = 1
	end
end


Re: Problems with quads

Posted: Thu Sep 19, 2013 10:32 pm
by SimonLarsen
It says the error appears on line 147 in main.lua but the code you've posted is only 127 lines long?

Re: Problems with quads

Posted: Fri Sep 20, 2013 1:01 am
by duiliomelhor
sorry, it's because I deleted a few lines of code in to comment the line 147 that says the error is as follows.

Code: Select all

love.graphics.drawq(Naruto_correndo, Naruto_correndo_quads[direction][iterator], 5, 5)

Re: Problems with quads

Posted: Fri Sep 20, 2013 4:18 am
by raidho36
Well, the "direction" variable obviously points to a table cell that doesn't exist, hence the error of indexing unexisting table.

See, whether you use one-line notation or define a variable for keeping each subtable, indexing (looking up the data by key) always happens sequentially. In fact, one-line notation is just an implicit shorthand for latter method, in the bytecode it would be about the same thing. Sequential indexing means that if any of the indexing fails on it's way to the rightmost index operator, the whole thing fails. This is why if you use sequential index notation you assume (and therefore make sure of) that all data would be valid under all circuimstances. Otherwise, you sequentially check all subsequent indexing results against nil. Using Lua's "logical" operator this may be done as following:

Code: Select all

return table[ a ] and table[ a ][ b ] and table[ a ][ b ][ c ]
Because the Lua operators are lazy, they will stop traversing clauses after first "breaker" (for the lack of better term) - a condition that makes any further processing meaningless because the ultimate result is already obtained. For "and" statement that would be a nil or false value. Thus, such line as above would first check if subtable A exists, after that subtable B of subtable A, and so on, until it reaches the last statement. If all previous checks haven't failed, the result would be the as defined in last statement, that is cell C in subtable B in subtable A. If any of them doesn't exist, the result would be nil and traversing will end abruptly saving the script from erroring.

Re: Problems with quads

Posted: Fri Sep 20, 2013 8:19 am
by Robin
Actually, the problem is that the default direction is "down" (as well as what it returns to when you release a key), while the only animations you defined are "a" and "d". Put in another for "down", and it'll probably work (though I can't tell, because you didn't upload a .love; please upload a .love next time).

Re: Problems with quads

Posted: Sat Sep 21, 2013 3:07 am
by duiliomelhor
thanks for the explanation guys, Robin I did what you said and created a more invez I put down to be "s", the game opens without further problem however if I click any key on the keyboard appears another error, follow the two imgens.

Code: Select all

require("Naruto")
require("Sasuke")
require("Kyubi")
require("Konoha")
local Quad = love.graphics.newQuad
function love.load()

--Carregar sprites naruto
Naruto_correndo = love.graphics.newImage(Naruto["Naruto_correndo"])



   --Animação do naruto
Naruto_correndo_quads = {

		s = {
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
		};

		a = {
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
		};
		d = {
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
			Quad(0,  0,  40, 45, 275, 102);
		};

	}
	iterator = 1
	max = 4
	timer = 0
	moving = false
	direction = "s"





--Carregar sprites Sasuke
corrida1_sasuke =love.graphics.newImage(Sasuke["sprites"])

--Carregar sprites Kyubi
invocacao_kyube =love.graphics.newImage(Kyubi["sprite"])

--Carregar imagem de fundo
imagem_fundo =love.graphics.newImage(Konoha["sprite"])

--Carregar som de fundo

musica_fundo = love.audio.newSource("sounds/musica_tema.mp3")
love.audio.play(musica_fundo)


end






function love.update(dt)


-- Movimento do Naruto


--if love.keyboard.isDown('s') then
 --Naruto.vel = 30
 --Naruto.cordy = Naruto.cordy + Naruto.vel * (10*dt)
--end
--if love.keyboard.isDown('w') then
 --Naruto.vel = -30
 --Naruto.cordy = Naruto.cordy + Naruto.vel * (10*dt)
 --end


if moving then
		timer = timer + dt
		if timer > 0.2 then
			timer = 0
			iterator = iterator + 1
			if iterator > max then
				iterator = 1
			end
		end
	end



-- Movimento do Sasuke

--if love.keyboard.isDown('down') then
 --Sasuke.vel = 30
 --Sasuke.cordy = Sasuke.cordy + Sasuke.vel * (10*dt)
--end
--if love.keyboard.isDown('up') then
 --Sasuke.vel = -30
 --Sasuke.cordy = Sasuke.cordy + Sasuke.vel * (10*dt)
--end
--if love.keyboard.isDown('left') then
--Sasuke.vel = -20
--Sasuke.cordx = Sasuke.cordx + Sasuke.vel * (10*dt)
--end
--if love.keyboard.isDown('right') then
--Sasuke.vel = 20
--Sasuke.cordx = Sasuke.cordx + Sasuke.vel * (10*dt)
--end

-------------------------------------------------
end







function love.draw()

--Mostrar imagem de fundo

   love.graphics.draw(imagem_fundo,Konoha.cordx,Konoha.cordy)


   love.graphics.print("Naruto vs Sasuke",285,300,0,2,2)




--Mostrar imagem Sasuke

   love.graphics.draw(corrida1_sasuke,Sasuke.cordx,Sasuke.cordy)


   -- Oyabin invocação
   if love.keyboard.isDown('i') then
      love.graphics.print("kushiose no jutsu",100,100)
	  love.graphics.draw(invocacao_kyube,Kyubi.cordx,Kyubi.cordy)
end




  --Animação do naruto ---------------------------------------

	love.graphics.drawq(Naruto_correndo, Naruto_correndo_quads[direction][iterator], 5, 5)

end

----------------------------------------
function love.keypressed(key)
	if Naruto_correndo_quads[key] then
		moving = true
		direction = key
	end
end
function love.keyreleased(key)
	if quads[key] and direction == key then
		moving = false
		direction = "s"
		iterator = 1
	end
end
T60EK2U.jpg
T60EK2U.jpg (215.98 KiB) Viewed 621 times
96mxzFJ.jpg
96mxzFJ.jpg (132.4 KiB) Viewed 621 times


PS: I wonder what it means to the first and senunda option of quads where is "0.0" it looked more in wiki did not quite understand, okay difficult to leave this animação.segue the spritesheet I'm using, maybe use only he ran to the left and to the right would be easier to do.

a1OD5PS.png
a1OD5PS.png (9.82 KiB) Viewed 621 times

Re: Problems with quads

Posted: Sat Sep 21, 2013 9:06 am
by Robin
In love.keyreleased, you wrote quads instead of Naruto_correndo_quads.

Also, next time please upload a .love. :)

Re: Problems with quads

Posted: Sat Sep 21, 2013 4:26 pm
by duiliomelhor
Robin the problem out thanks this time was pure lack of attention now because the animation does not occur, and I'm sure there is a setting in the sprite quads.segue the compressed folder with. love.

Re: Problems with quads

Posted: Sun Sep 22, 2013 8:28 am
by Robin
duiliomelhor wrote:Robin the problem out thanks this time was pure lack of attention now because the animation does not occur, and I'm sure there is a setting in the sprite quads.segue the compressed folder with. love.
I can't follow you. Is the problem solved now? (I can't try out your game, because uploaded a .rar file. A .love file is generally a renamed .zip.)