4 ms·
I think it's just a case of leaky abstraction. I'd change the API to something like: robot.action = { action: 'jump' }; robot.action = { action: '
by kaoD 9y ago
I think it's just a case of leaky abstraction. I'd change the API to something like:
robot.action = { action: 'jump' };
robot.action = { action: 'move', amount: 4 };
etc.
Or if you want to keep the action creators:
robot.action = robot.jump();
robot.action = robot.move(4);
Which makes it obvious that there can only be a single action per loop call.
- reacweb 9y agoOr the action could be the return value. IMHO, trying to guess the physical model by experimentation is painful. Why not propose a debug button to display the state of variables during the execution of script.
- positivecomment 9y agoExactly, the function should not be responsible to see if robot.action has any existing value. It should just return an action depending on the state.
- always_good 9y agoAnother idea is to return a map of actions. { jump: true, move: 4, shoot: true } Making the user increment a nonce and use the remainder operator just to do multiple actions simultaneously is pretty heavy.