Barba-negra 117 Posted July 10, 2019 Hello friends how are you? I come here asking for help to know if you can help me, because I am trying to do an action when I press a key and looking for this scripts: keydown_fnc = { switch (_this) do { { case _x: { [] spawn { _truck1 setVelocity [0, 10, 0]; }; }; } foreach (actionkeys "MoveForward"); }; }; waituntil {!isnull (finddisplay 46)}; (findDisplay 46) displayAddEventHandler ["KeyDown","_this select 1 call keydown_fnc;false;"]; my problem is that I need that when I release the key (keyup) _truck1 it stops and emits a motor noise stopping, how can I complete this scripts? please help, thanks Share this post Link to post Share on other sites
pierremgi 4900 Posted July 10, 2019 setVelocity is not supposed to be persistent and never gives a destination (waypoint). So it's normal that engine stops, wheels don't turn, like the truck at stop. The good question is: what do you intend to do with that? There is probably (not sure) another solution. Share this post Link to post Share on other sites
Barba-negra 117 Posted July 10, 2019 if you were testing it directly and it is not persistent, you are right, however if you want to raise the key another option occurs so you can create another line in the same script can work? example: keydown_fnc = { switch (_this) do { { case _x: { [] spawn { hint " first action"; }; }; } foreach (actionkeys "MoveForward"); }; }; keyUp_fnc = { switch (_this) do { { case _x: { [] spawn { hint "second action"; }; }; } foreach (actionkeys "MoveForward"); }; }; waituntil {!isnull (finddisplay 46)}; (findDisplay 46) displayAddEventHandler ["KeyDown","_this select 1 call keydown_fnc;false;"]; (findDisplay 46) displayAddEventHandler ["KeyUp","_this select 1 call keyUp_fnc;false;"]; Share this post Link to post Share on other sites
Barba-negra 117 Posted July 11, 2019 12 hours ago, pierremgi said: setVelocity is not supposed to be persistent and never gives a destination (waypoint). So it's normal that engine stops, wheels don't turn, like the truck at stop. The good question is: what do you intend to do with that? There is probably (not sure) another solution. I just found what I was looking for here Share this post Link to post Share on other sites
Barba-negra 117 Posted July 11, 2019 I need a help please, I have managed to make the script work, but it is giving me a problem, and that is that the keydown key is repeated again and again while I keep it pressed, I need to make it repeat only once while I keep it pressed, how can I do it?? [] spawn { waitUntil {!isNull findDisplay 46}; (findDisplay 46) displayAddEventHandler ["keyDown","_this call fnc_keyDown"]; (findDisplay 46) displayAddEventHandler ["keyUp","_this call fnc_keyUp"]; }; fnc_keyDown = { _dikCode = _this select 1; if (_dikCode in actionKeys "MoveForward") then { hint "hola"; true }; }; fnc_keyUp = { _dikCode = _this select 1; if (_dikCode in actionKeys "MoveForward") then { hint "chao"; true }; }; keyUp works correctly does not repeat, but keydown does it again and again and that is the problem, help please Share this post Link to post Share on other sites
pierremgi 4900 Posted July 11, 2019 That's 2 separate events if you're not too close to a black hole horizon. Key down is something "repeatable", lasting the time you press the key. These is no reason to do that for key up. If you want to make these codes interact, try to add a conditional variable: for key down: if ((_dikCode in actionKeys "MoveForward" && isNil "blaBlaKey") then { blaBlaKey = true; your code....}; for key up : if (_dikCode in actionKeys "MoveForward") then { blaBlaKey = nil; your code...} (not tested) 1 Share this post Link to post Share on other sites
Barba-negra 117 Posted July 11, 2019 thanks @pierremgi I'm going to do it and I'll tell you the result Share this post Link to post Share on other sites
Barba-negra 117 Posted July 12, 2019 https://ibb.co/j8TwsML This is the error that it gives me, I'm doing it just like you did Share this post Link to post Share on other sites
Barba-negra 117 Posted July 12, 2019 another voice, is working, had copied something wrong, thank you very much @pierremgi Share this post Link to post Share on other sites