Page 1 of 1

Love for Lua Game Programming chapter 2 problem

Posted: Mon Sep 07, 2015 11:10 pm
by Zace66
I'm getting a problem with the following code... it doesn't like line 17 or 20 ( character.x = character.x – 1 * dt ) ( y-1)
Is this because the book was written a few years ago and things have moved on - if so is there a better book recommended to learn from please?
Sorry if this has been asked before but searching the forums didn't show anything up.

Code: Select all

function love.load()
	character = {}
	character.x = 300
	character.y = 400
	love.graphics.setBackgroundColor(225, 153, 0)
	love.graphics.setColor(0, 0, 225)
end

function love.draw()
    love.graphics.rectangle("fill", character.x, character.y, 100, 100)
end

function love.update(dt)
	if love.keyboard.isDown('d') then
		character.x = character.x + 1 * dt
	elseif love.keyboard.isDown('a') then
		character.x = character.x – 1 * dt
	end
	if love.keyboard.isDown('w') then
		character.y = character.y – 1 * dt
	elseif love.keyboard.isDown('s') then
		character.y = character.y + 1 * dt
	end
end

Re: Love for Lua Game Programming chapter 2 problem

Posted: Tue Sep 08, 2015 12:08 am
by airstruck
Those aren't minus signs, they're "U+2013 EN DASH"

Re: Love for Lua Game Programming chapter 2 problem

Posted: Tue Sep 08, 2015 3:16 pm
by zorg
On another note, this issue came up more than once, so i'd be interested to know what kind of code editor (or system locale) messes with the minus sign.

Re: Love for Lua Game Programming chapter 2 problem

Posted: Tue Sep 08, 2015 6:19 pm
by airstruck
zorg wrote:On another note, this issue came up more than once, so i'd be interested to know what kind of code editor (or system locale) messes with the minus sign.
Probably some typesetting software did that and code was copypasted from book.

Re: Love for Lua Game Programming chapter 2 problem

Posted: Tue Sep 08, 2015 6:48 pm
by Zace66
Good old Notepad++, sigh, ive seen this before when coding PHP.

Arghh - sorry for bothering you (Shame on me for shortcutting the typing and relying on copy and paste)

Mind you the keys don't respond, or rather I don't see any movement or rotation. Sigh.

Re: Love for Lua Game Programming chapter 2 problem

Posted: Tue Sep 08, 2015 7:24 pm
by arampl
Just download example code for the book and use it.