Page 1 of 1

Require won't work :s

Posted: Mon Apr 09, 2012 8:55 pm
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'

Re: Require won't work :s

Posted: Mon Apr 09, 2012 9:08 pm
by bartbes
You call love.draw in love.draw, and you should be calling love.graphics.draw.

Re: Require won't work :s

Posted: Mon Apr 09, 2012 9:09 pm
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

Re: Require won't work :s

Posted: Mon Apr 09, 2012 9:12 pm
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'

Re: Require won't work :s

Posted: Mon Apr 09, 2012 9:32 pm
by Robin
You never call the function player(). Just call it in love.load() or something.

Re: Require won't work :s

Posted: Mon Apr 09, 2012 9:43 pm
by Pigzo
Works Perfectly Thank!

I Up You Karma