Probably a very simple case of using functions incorrectly
Posted: Sat Jul 21, 2012 12:58 am
The following is the essence of my main.lua file. The problem is that the moveObject function doesn't work, even though the exact same code works when not part of a function. Why is this? Am I doing something wrong?
The following code should feature a rectangle that does not move, since it has two equal but opposite sets of instructions acting on it. But right now one set of code works, while the other (the one inside moveObject()) does not.
The following code should feature a rectangle that does not move, since it has two equal but opposite sets of instructions acting on it. But right now one set of code works, while the other (the one inside moveObject()) does not.
Code: Select all
function love.load()
ox,oy=0,0 -- object coordinates
function moveObject(ox,oy,s,dt) --should move object diagonally
ox=ox+s/2*dt oy=oy+s/2*dt
end
end
function love.update(dt)
local s=100 -- set the speed
--because the moveObject function uses negative s, the next two lines of code SHOULD cancel each other out. Right now that doesn't work.
moveObject(ox,oy,-s,dt)
ox=ox+s/2*dt oy=oy+s/2*dt
end
function love.draw()
love.graphics.rectangle('line',ox,oy,10,10)
end