Beginner Coding Problem

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
rockstar0419
Prole
Posts: 6
Joined: Wed Dec 04, 2013 10:30 pm

Beginner Coding Problem

Post 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?
bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

[]

Post by bekey »

-snip-
Last edited by bekey on Fri Jan 24, 2014 2:17 am, edited 1 time in total.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Beginner Coding Problem

Post 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 :)
rockstar0419
Prole
Posts: 6
Joined: Wed Dec 04, 2013 10:30 pm

Re: Beginner Coding Problem

Post by rockstar0419 »

Alright, thanks. I see where I went wrong there.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests