Page 1 of 1

Beginner Coding Problem

Posted: Tue Dec 10, 2013 11:13 pm
by rockstar0419
In my simple game, you must rebuild your houses after a natural disaster. But it seems that I have run into a dilemma. When the "z" key is pressed, I want a house drawn, given there is 50 lumber in the stockpile. During the debugging, when I press the "z" key, no house appears, nor is 50 lumber subtracted.
Here's the code:

Code: Select all

smallshack = love.graphics.newImage("smallshack.png")
function love.keypressed(key)
if key == "z" then 
lumber = lumber - 50
love.draw()
x = 200
y = 200
love.graphics.draw(smallshack, x, y)
end
end
I don't understand the problem. Could you possibly explain to me my errors?

[]

Posted: Tue Dec 10, 2013 11:18 pm
by bekey
-snip-

Re: Beginner Coding Problem

Posted: Tue Dec 10, 2013 11:45 pm
by MadByte
Welcome on the forums :)
rockstar0419 wrote:

Code: Select all

smallshack = love.graphics.newImage("smallshack.png")
function love.keypressed(key)
if key == "z" then 
lumber = lumber - 50
love.draw()
x = 200
y = 200
love.graphics.draw(smallshack, x, y)
end
end
You might want to try out some tutorials first, mainly to learn how to work with the lua main loops ( love.load, love.update, love.draw ).
Another great way to learn things is to look at other people's source code ( just said if you don't know it already ;] )

on topic:
Heres a pretty ugly, but hopefully easy to understand example of what you want to happen.
houses.love
You can open the file with any .zip unpacking tool and look at the source.
Maybe this simple example help somehow. If you've further questions, feel free to ask :)

Re: Beginner Coding Problem

Posted: Wed Dec 11, 2013 12:09 am
by rockstar0419
Alright, thanks. I see where I went wrong there.