Game Development Community

Continuous action on key press

by Mr.Trance · in General Discussion · 01/25/2010 (4:15 am) · 2 replies

Hello

using script function
moveMap.bindCmd(keyboard, "w", "onPressedFunc();", "onReleasedFunc();");
the function onPressedFunc() is called once the key is pressed, and the other one - when the key is released.

So, what if I want to repeat the action, that is described in onPressedFunc(), for as long as I hold the "w" key? For example, the continuous fire while folding space key, or the same "w" key.

About the author

Young indie game developer from far far city.


#1
01/25/2010 (4:47 am)
The easiest way, in my opinion, is to start a schedule on the make-key function (onPressedFunc in your case) and cancel it on the break-key function.
#2
01/25/2010 (8:53 am)
your onPressedFunc, if defined in default.bind.cs, should have a %val argument passed to it everytime you press the "w" button. %val is usually either a 0 or a 1 (false or true) and if you interogate that arg you can start and stop the function...

function onPressedFunc(%val)
{
if(%val)
//fire...
}

as long as the "w" button is depressed %val will be 1. Once it is released %val will be 0. NOTE this does NOT hold true for mouse button presses ie. no continuos function calls by holding the mouse button down.