Page 1 of 1

Help with errror

Posted: Thu Feb 06, 2014 8:05 pm
by jnbutler
I am getting the error message,
main.lua:29:attempt to call method 'flip'(a nil value)

here is the function that contains that line of code highlighted in yellow.
I'm new at Love, please help.

Code: Select all

function love.load() ---loads all we need in game
	
	character = {}
	character.player = love.graphics.newImage "gripe.run_right.png"
	character.x = 50
	character.y = 50
	direction = "right"
	iteration = 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);
		-- for the characgter to face the opposite
		-- direction, the quad needs to be flipped
		-- by using the Quad:flip(x,y) method, where
		-- x and y are Boolean.

		[color=#FFFF00]quads.left[j]:flip(true, false)[/color] --flip horizontaly x = true, y = false
	end
	
end

Re: Help with errror

Posted: Thu Feb 06, 2014 8:25 pm
by davisdude
Change line 4 to:

Code: Select all

character.player = love.graphics.newImage( "gripe.run_right.png" )
As for your "Quad:flip" function, it's either in another file or never been made, because it's not on the wiki, and as far as I know, does not exist.

That being said, you could create one very simply:

Code: Select all

local Quad = {
     -- Quad information goes in here.
}

function Quad:flip( sx, sy ) -- sx, sy = new scale for Quad.
     self.sx, self.sy = nx, ny
end

Re: Help with errror

Posted: Thu Feb 06, 2014 8:37 pm
by JovialFeline
^ Quad:flip
Removed in LÖVE 0.9.0
This function is not supported in that and later versions.

Re: Help with errror

Posted: Thu Feb 06, 2014 8:47 pm
by jnbutler
Thanks #davisdude and #jovialfeline for your quick responses.

I guesss I'll have to use your flip function that you provided davisdude.
Thanks again.

Re: Help with errror

Posted: Thu Feb 06, 2014 8:48 pm
by slime
For a replacement to Quad:flip, you should draw the un-flipped quad with a negative scale.
For example:

Code: Select all

love.graphics.draw(image, quad, x, y, angle, -1, 1)
You might also want to use half the image's width and height for the ox and oy parameters of love.graphics.draw, so it's drawn (and rotated and scaled) from the image's center.

Re: Help with errror

Posted: Fri Feb 07, 2014 6:26 pm
by Kingdaro
Off-topic, but why does angle come before scale and offset? It seems like more people would use offset and scaling with an angle of 0 than they would actually use the angle without scaling or offset. Just something I've always wondered.

Re: Help with errror

Posted: Sun Dec 07, 2014 3:17 am
by osgux
hi!
I have the same problem, but I don't know so much about lua, here you are my code

https://gist.github.com/marti1125/c99c8bb2dff05cdfe4dd

I hope we can help me =D