I'm a noob to coding, something basic isnt working how I thought it would.
Okay so I wanted to make arrow key movements for my character, and it isn't working. the code for this function is:
function moveCharacter("Knight") -- Opening parenthesis correctly added here
if key(UP) then
y = y - 2 -- Move up
end
if key(DOWN) then
y = y + 2 -- Move down
end
if key(LEFT) then
x = x - 2 -- Move left
end
if key(RIGHT) then
x = x + 2 -- Move right
end
end
Does anyone have any ideas?
here is a basic snippet to get you started:
update = function()
if keyboard.UP then y = y + 2 end
if keyboard.DOWN then y = y - 2 end
if keyboard.LEFT then x = x - 2 end
if keyboard.RIGHT then x = x + 2 end
end
draw = function()
screen.clear(0)
screen.drawSprite("icon", x, y, 16, 16)
end
(btw, if you use ``` before and after your code that you post here, it will format it nicely)
Did you define the key
function and the UP, DOWN, LEFT, and RIGHT variables? For keyboard inputs, you can use keyboard.UP
, keyboard.DOWN
, keyboard.LEFT
, and keyboard.RIGHT
.