Require won't work :s

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
Pigzo
Prole
Posts: 17
Joined: Mon Apr 09, 2012 8:49 pm

Require won't work :s

Post by Pigzo »

Hey Guys i have a Problem with Love 0.8.0 I Programmed a New Game(N00b Like xD) and i made a player.lua .. i'll post the complete code..

main.lua

Code: Select all

require 'player'

function love.load()	
	mediumFont = love.graphics.newFont(20)
	bg_color()
end

function love.update(dt)
	if love.keyboard.isDown("right") then
		player_x = player_x + (speed * dt)
	elseif love.keyboard.isDown("left") then
		player_x = player_x - (speed * dt)
	end

	if love.keyboard.isDown("up") then
		player_y = player_y - (speed * dt)
	elseif love.keyboard.isDown("down") then
		player_y = player_y + (speed * dt)
	end
end

function love.draw()
	love.draw(player_mob, player_x, player_y)
	love.graphics.setFont(mediumFont)
	setColor("black")
	love.graphics.print("Start Game", 5, 5)
	resetColor()
end

function bg_color()
	love.graphics.setBackgroundColor(187, 255, 129)
end

function setColor(color)
	if color == "black" then
		love.graphics.setColor(0, 0, 0)
	end
end

function resetColor()
	love.graphics.setColor(255, 255, 255)
end




player.lua

Code: Select all

function player()
	player_mob = love.graphics.newImage("Data/mob/player.png")
	player_x = 200
	player_y = 200
	speed = 400
end
Everytime i Started this i became this warning from Love

Error

main.lua:23: stack overflowed

Traceback

main.lua:23: in function 'draw'
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Require won't work :s

Post by bartbes »

You call love.draw in love.draw, and you should be calling love.graphics.draw.
User avatar
Adamantos
Prole
Posts: 27
Joined: Sun May 16, 2010 10:47 pm

Re: Require won't work :s

Post by Adamantos »

Hey,

You are causing a recursion in love.draw(), i.e. love.draw is calling itself over and over again... until there is no memory left. You are looking for the love.graphics.draw(...) funtion.

Code: Select all

function love.draw()
   love.graphics.draw(player_mob, player_x, player_y)
   ...
end
Pigzo
Prole
Posts: 17
Joined: Mon Apr 09, 2012 8:49 pm

Re: Require won't work :s

Post by Pigzo »

Well Now i Became this Error ...

Error

main.lua:23: Incorrect parameter type: expected userdata.

Traceback
[C]: in function 'draw'
main.lua:23: in function 'draw'
[C]: in function 'xpcall'
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Require won't work :s

Post by Robin »

You never call the function player(). Just call it in love.load() or something.
Help us help you: attach a .love.
Pigzo
Prole
Posts: 17
Joined: Mon Apr 09, 2012 8:49 pm

Re: Require won't work :s

Post by Pigzo »

Works Perfectly Thank!

I Up You Karma
Post Reply

Who is online

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