[SOLVED] Problem with simple code

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
falk
Prole
Posts: 1
Joined: Tue Nov 29, 2016 10:22 pm
Location: Primiseland

[SOLVED] Problem with simple code

Post by falk »

Hey, guys! I'm completely new to programming and game development. I'm also not a native English speaker, so I'd like to apologize for all my language mistakes and idiotic questions in advance.
I use love2d version 0.10.1 and Lua version 5.2. I downloaded them some time ago, but started learning yesterday. But no more procrastination! With your help I'll become a game developer and I'll release a game before my death (did I mention I'm quite old?).
I've written some simple code and it doesn't work as I expected:

Code: Select all

local x, y, side
function love.load()
  x = love.graphics.getWidth() / 2 - 10
  y = love.graphics.getHeight() /2 - 10
  side = 20
end

function love.update(dt)
  if love.keyboard.isDown('up') then
    y = y - 20 * dt
  end
  if love.keyboard.isDown('down') then
    y = y + 20 * dt
  end
  if love.keyboard.isDown('left') then
    x = x - 20 * dt
  end
  if love.keyboard.isDown('right') then
    x = x + 20 * dt
  end
  if love.keyboard.isDown('space') then
    side = side + 50 * dt
  end
end

function love.draw()
  love.graphics.rectangle('fill', x, y, side, side)
end
So, I can go up, down, left, right, diagonal (by pressing two buttons), I can enlarge the square even when I move except (and that's something I cannot understand) when I move diagonally left-up. Pressing space when I already hold up and left arrow pressed does nothing (and it should enlarge the square). Also, when I hold the space button I can move any direction except left-up (so when I hold space bar pressed, pressing up and left arrow simultaneously doesn't do anything, the square is enlarging but not moving).
Any idea what's wrong? I'm not very bright, so I can't figure it out by myself. Help the old man, please.

EDIT: it's a ghosting issue (thing I have never heard of before). CHEERS for the answer!
Last edited by falk on Wed Nov 30, 2016 12:39 pm, edited 1 time in total.
Goal: World conquest
3-phase plan:
1- learn how to make games
2- ?????????????????????
3- World domination
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: Problem with simple code

Post by Beelz »

It would assume it's a ghosting issue like explained here.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
Post Reply

Who is online

Users browsing this forum: qq1723 and 4 guests