I want to increment the keyState
variable, but it does not seem to change.
This is my code at the moment:
local keyState: number = 0
local function setControlCallback(key: string)
local direction: number = (key == upKey) and 1 or -1
self.callbackIds[key] = self.controlInput:SetCallback(
function(event: string)
print(keyState)
if event == "InputBegan" then
keyState = keyState + direction
elseif event == "InputEnded" then
keyState = keyState - direction
end
print(keyState, direction)
end,
key,
function()
keyState = keyState + direction
end
)
end
The issue is that if keyState
is 0 and direction
is 1, my output will print
0
0 1
, eventhough I incremented keyState
with direction
. What I hoped to see is a succesful increment operation:
0
1 1
I have tried to use the +=
and -=
operators, but that did not fix the issue (I still use them cause it saves some characters).