I'm having a problem with KeyPressed and KeyDown2. It only exists in v3/4, not v2, so it might belong in the Bugs section.
When the 's' key is caught with KeyPressed, a system sends a trigger to another NPC. However, I only want it to send the trigger once, not multiple times.
Originally, I set a flag that says the key was pressed, then use a timeout to check for when the player lets go of the key. When the player lets go of the key, it unsets the flag.
This doesn't work. While I'm holding down the 's' key, it continually calls the KeyPressed function, but KeyDown2 returns it as not being pressed.
NPC Code:
function onKeyPressed(code,key) {
if (key == "s" && this.holding == false) {
findweapon("Blah").trigger("DoSomething",NULL);
this.holding = true;
setTimer(.05);
}
}
function onTimeout() {
if (this.holding == true) {
if (!keydown2(getkeycode("s"),false)) this.holding = false;
setTimer(.05);
}
}
EDIT: My bad, I was using keycode() instead of getkeycode(). Changing it to getkeycode() made it work properly. This might have something to do with the hammer bug on GK?