advice
3 TopicsButton Listener to move a character
Hello everyone I've dealing with a problem, I started a project, it is supposed to be an Escape Room, and most of the things I need for it are already available on Storyline. But I've been stuck on the movement of the character, it is a simple 2D movement, right and left, inside the room. The problem is: I already got it to move on a click, but it is just on that click, I want it to move as long as I keep the button pressed. This is the last JavaScript I tried to make it move: const button = object('5yfHufFxicy'); function moveWhilePressed() { button[i].addEventListener("mousedown",() =>{ const player = GetPlayer(); player.GetVar("MousePressed"); const currentX = player.GetVar("MoveX"); player.SetVar("MoveX", currentX +1); setTimeout(moveWhilePressed, 100); const objects = [ object('6EPGwyDzEfX'), ]; const positions = objects.map(obj => ({ x: obj.x})); objects.forEach((obj, i) => { obj.x = positions[i].x+currentX; }); }); } moveWhilePressed(); Not sure if I'm wrong on the EventListener, before I added it, the character moved, but the moment I clicked, it kept moving without the button pressed. I tried using Variables, but the result was the same, the character kept moving.Solved206Views1like4Comments