problem with Hookkey()
Displaying 1-13 of 13 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Technetium

In my map vc file I have:
hookkey(key[SCAN_ESC],"menu");

This line is the last line contained in my start function. Everything else in the start function runs fine.

In my system.vc I have:
#include "menu.vc"


In menu.vc I have:

void menu()
{
log("got this far");
menuopen=1;
menuchoice[0]=0;
if(MenuMemory)
{
menuchoice[0]=MM_Main;
}
while(menuopen==1)
{
render();
gradientwindow(5,5,100,300);
showpage();
}
log("exited menu incorrectly");
}


When I press ESC once gaining control of the player character, it doesn't do anything. Verge.log doesn't even pick up the log() statements from the menu function.

Posted on 2004-07-03 17:38:19

Interference22

Have you tried hookkey(b3,"menu")? I think hookkey wants a button rather than a scancode, not sure though.

Posted on 2004-07-03 18:13:47 (last edited on 2004-07-03 18:14:08)

mcgrue

Also, unless I'm off my rocker,

key[ANY_VALID_VALUE_HERE]

will always either evaluate to 0 or 1... since they key[SCAN_CODE] array is used for verifying if the key that the index represents is being pressed.

So that first snippet of code is fundamentally wrong. ditch the key[], and just leave the SCAN_CODE.

Here's an example from my Sully codebase-in-progress:


HookKey( SCAN_F10, "SaveScreenShot" );
HookKey( SCAN_F4, "mcg_print_all" );


These are temporary hookkeys, one to the screenshot function that one of you blokes out there coded (Zip? Ger? I forget offhand), and another to a heavy-duty logging function for debugging purposes.

Any questions?

Posted on 2004-07-03 18:35:16

vecna

Grue is mostly correct. You want to call HookKey with SCAN_F10 not key[SCAN_F10]. The only exception is that they do not evaluate to 0 or 1, they evaluate to 0 or non-zero... still true/false, but you shouldn't test for 1.

Posted on 2004-07-03 18:48:55

mcgrue

Really? Out of sheer curiosity, what does each one light up with when active... their scancode's value?

But that's very right, kids. When testing the key array, do it like so:


if( key[SCAN_F10] ) {
log( "F10 was molested!!!" );
}


NOT:

if( key[SCAN_F10] == 1 ) {
log( "THIS IS BAD WRONG BADONG!!!" );
}

Posted on 2004-07-03 19:00:08

Zip

Not just a bool 0/1 value? Does the number store any useful information, like how many times the key has been pressed then?

On the subject of keys, as the state array is HasKeyBeenPressed rather than IsKeyPressed, what's the easiest way to see if someone is holding a key down?

Zip

Posted on 2004-07-03 19:50:47

Technetium

You guys rock. Thanks!

Posted on 2004-07-03 23:33:42

Interference22

I really should get to work contributing some more to the online docs some time, shouldn't I?

Posted on 2004-07-04 00:03:14

RageCage

if someone presses a key, the key[] value will be non-zero. if they're still pressing the key then it will still be non-zero. if they release the key it will be 0 once more.

Posted on 2004-07-04 07:23:14

Kildorf

Quote:Originally posted by RageCage

if someone presses a key, the key[] value will be non-zero. if they're still pressing the key then it will still be non-zero. if they release the key it will be 0 once more.

Unless, of course, the key[] value was set to zero. It only gets set right when the button is pushed, not continuously as it is held down.

Posted on 2004-07-04 08:35:03

vecna

Yeah, it IS 'is key pressed' not 'has key been pressed'. If the key is held, it will remain true, unless you manually set it to 0. When you set a key to zero you are effectively unpressing it.

As to the non-zero value of the key, Idunno, its just the value that directinput gives me.

Posted on 2004-07-05 18:14:17

Zip

[Edit: Well, some experimentation reveals that this is the case, I'd just misintepreted the input stuff before. Learn something everyday. Well, you do when people answer you :D]
Fair enough on the value.

Zip

Posted on 2004-07-05 18:18:52 (last edited on 2004-07-05 18:35:26)

vecna

It sets the values back to 0 when the key is released, yes. For keys and for buttons, but obviously buttons have a more complicated unpress system involved.

All key updates occur when updatecontrols/showpage happens. If you are in a loop where you aren't doing either, you wont detect ANY key status change. A loop without showpage is silly though!

Posted on 2004-07-05 18:34:54


Displaying 1-13 of 13 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.