Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Key-Press detection and Game speed control in HPL3
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#1
Key-Press detection and Game speed control in HPL3

Hey guys, two quick questions about HPL3. I can't seem to find info in the wiki about this.
Are there any new functions related to key-press detection or how to control the game speed? just like we do in dev mode.
Thanks.

I may be working in something but I don't wanna reveal anything until I'm completely sure I can do it. You know what I mean.

06-18-2016, 08:31 PM
Find
Abion47 Offline
Senior Member

Posts: 369
Threads: 22
Joined: Oct 2015
Reputation: 46
#2
RE: Key-Press detection and Game speed control in HPL3

There are a couple of ways to detect key presses.

The first and easier way is to watch the OnAction function of your map script for whenever the player initiates an action, e.g. eAction_Forward, eAction_Interact, eAction_Cancel (the eAction enumeration is in the "script/base/InputHandler_Types.hps" file if you want to see the full list of actions available). The benefit to this is that the key is automatically routed through the game's keybindings, so you can always detect a particular action regardless of what key it is bound to. The downside to this approach is that you are limited to only using existing actions in the game (though you can add more if you know how).

To check against a particular action, you compare the alAction parameter against whichever action you are watching for:

bool OnAction(int alAction, bool abPressed)
{
    // Check if the interact action was started (and if the key was pressed rather than released)
    if (alAction == eAction_Interact && abPressed)
    {
        // Do stuff...
    }
}

The other way is a bit more involved (and I haven't tested it yet myself, so I can't vouch for its effectiveness). You can get an instance of the iKeyboard object and manually detect if certain keys are being pressed (using the eKey enumeration). This has the benefit of allowing you to check the state of any key you want, but the downside of possible collisions with existing keybindings. You would also have to put it in your map's Update script if you wanted to continuously check for key presses which could potentially affect performance (though probably not by much).

void Update(float afTimeStep)
{
    iKeyboard @keyboard = cInput_GetKeyboard();

    // Check if the key is pressed (note that this will return true for as long as the key is held down)
    if (keyboard.KeyIsDown(eKey_E))
    {
        // Do stuff...
    }
}
06-18-2016, 09:07 PM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#3
RE: Key-Press detection and Game speed control in HPL3

Great. I'll look into it.
rep++

it worked.

(This post was last modified: 06-18-2016, 11:58 PM by Daemian.)
06-18-2016, 11:37 PM
Find




Users browsing this thread: 1 Guest(s)