Help with errror

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
jnbutler
Prole
Posts: 2
Joined: Thu Feb 06, 2014 7:54 pm

Help with errror

Post 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
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: Help with errror

Post 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
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
JovialFeline
Prole
Posts: 28
Joined: Wed Jan 08, 2014 2:32 pm

Re: Help with errror

Post by JovialFeline »

^ Quad:flip
Removed in LÖVE 0.9.0
This function is not supported in that and later versions.
jnbutler
Prole
Posts: 2
Joined: Thu Feb 06, 2014 7:54 pm

Re: Help with errror

Post 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.
User avatar
slime
Solid Snayke
Posts: 3160
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Help with errror

Post 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.
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Help with errror

Post 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.
osgux
Prole
Posts: 1
Joined: Sun Dec 07, 2014 3:14 am

Re: Help with errror

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

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest