Page 1 of 1

A quick error I just cant find

Posted: Fri Sep 12, 2014 11:43 pm
by BEANSFTW
This should have been a direct copy and paste from one of my templates, but I'm getting an error anyways. seems like a simple problem but I just can't find where it is. The error is

Code: Select all

Syntax error: player.lua:62: '<eof>' expected near end
and this is my love.lua and player.lua:

main.lua-

Code: Select all

require "player"


function love.load()

	
	love.graphics.getBackgroundColor(0,0,0)

	player.load()
	
	glev = 550
	
	gravity = 900
	
end

function love.update(dt)

	UPDATE_PLAYER(dt)


end

function love.draw()

	DRAW_PLAYER()

end
player.lua-

Code: Select all

player = {}
	
function player.load()
	
	player.x = 5
	player.y = 5
	player.xvel = 0
	player.yvel = 0
	player.friction = 7
	player.speed = 2250
	player.width = 50
	player.height = 50
	
end

function player.draw()

	love.graphics.setColor(255,0,0)
	love.graphics.rectangle("fill",player.x,player.y,player.width, player.height)

end

function player.physics(dt)

	player.x = player.x + player.xvel * dt
	player.y = player.y + player.yvel * dt
	player.vel = player.yvel + gravity * dt
	player.xvel = player.xvel * (1 - math.min(dt * player.friction, 1))
	player.yvel = player.yvel * (1 - math.min(dt * player.friction, 1))

end

function player.move(dt)

	if love.keyboard.isDown('right') and
	player.xvel < player.speed then
		player.xvel = player.xvel + player.speed * dt 
	end
	
	if love.keyboard.isDown('left') and
	player.xvel > -player.speed then
		player.xvel = player.xvel - player.speed * dt 
	end

end

function player.collision()

	if player.x < 0 then
		player.x = 0
		player.xvel = 0
	end	
	
	if player.y + player.height > glev then
		player.y = glev - player.height
		player.yvel = 0
	end	

end

function UPDATE_PLAYER(dt)

	player.physics(dt)
	player.move(dt)
	player.collision()
	
end

function DRAW_PLAYER()
	player.draw()
end

Re: A quick error I just cant find

Posted: Sat Sep 13, 2014 12:13 am
by Snackrilege
There is almost certainly no end of file error in that player code... you're certain you posted all of it ( even comments, etc) ?

Re: A quick error I just cant find

Posted: Sat Sep 13, 2014 1:24 am
by BEANSFTW
Did you try running the game and seeing if it got an error? from a first glance, it really doesn't look like it has an error. maybe it's the version of love, but still.

Re: A quick error I just cant find

Posted: Sat Sep 13, 2014 1:35 am
by Snackrilege
Whoops, sorry to leave you hanging!

I just ran the code and was not stopped by the compiler. It displayed a red rectangle in the top right corner of a black screen.

Keep up the good fight, my friend, I know how painful it is to have to debug your debugger. Probably the worst experience in coding.

Re: A quick error I just cant find

Posted: Sun Sep 14, 2014 12:36 pm
by undef
Maybe you didn't save the changes in all files? Player.lua in this example.
(Maybe you're actually editing a backup at a different location?)

It's always easiest if you just create and upload a .love file, and check if the file works on your computer. If not - upload it.
It's much more convenient for those willing to help as well.

Re: A quick error I just cant find

Posted: Mon Sep 15, 2014 12:28 am
by BEANSFTW
thx guy for the support, i got the thing working by putting the variables in the player.lua.