Posted 21 July 2015 - 07:45 AM
I know the title isn't very descriptive, I didn't really know what to put there.
I am trying to create a space that the player (&) can move around in. I created some really basic code for it, but the code doesn't work, and I really don't know why, but I think it is something with os.pullEvent("key") that I did wrong. Here is the code:
I am trying to create a space that the player (&) can move around in. I created some really basic code for it, but the code doesn't work, and I really don't know why, but I think it is something with os.pullEvent("key") that I did wrong. Here is the code:
Spoiler
-- BASE VARS --
charX = 1
charY = 1
-- START CODE -
function changePos()
key = os.pullEvent("key")
if key == keys.w then
charY = charY-1
end
if key == keys.s then
charY = charY+1
end
if key == keys.d then
charX = charX+1
end
if key == keys.a then
charX = charX-1
else
changePos()
end
end
function drawPos()
term.clear()
term.setCursorPos(charX,charY)
print("&")
end
function code()
changePos()
drawPos()
term.setCursorPos(1,1)
print(charX,",", charY)
end
code()
code()
code()
code()
code()