I’ve been going through the tutorials and this portion confused me.
- For each input direction, set the X or the Y component of the
input
vector inself
. If the user presses the up arrow and left arrow keys simultaneously, the engine will call this function twice and the input vector will end up being set to(-1, 1, 0)
.
and here is the relevant code snippet
function on_input(self, action_id, action) -- [14]
if action_id == hash("up") then
self.input.y = 1 -- [15]
elseif action_id == hash("down") then
self.input.y = -1
elseif action_id == hash("left") then
self.input.x = -1
elseif action_id == hash("right") then
self.input.x = 1
end
...
end
My question is regarding the elseif in particular, and I guess the caveat here is the fact that the engine calls the function twice.
So is the resulting logic that both calls from the player input are sent to on_input before update is ever called so both self.input.x and self.input.y have been set?
Thanks for the help!