Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (AndrewAMD, TipmyPip), 12,420 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Typematic rate for key press or better option? #151376
08/31/07 17:45
08/31/07 17:45
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21

if(key_o)
{
show_debug();
}


The problem with this is that it detects the key press every frame and runs the function each time. Is there a good method for only detecting the key press and then waiting for the release before running again?

I've been using somthing along these lines, but it seems sloppy and requires a lot of varriables.


if(!key_space)
{
jumping=0;
}
// Jump
if(key_space)
{
if(!jumping)
{
vec_set(temp, my_entity.x);
temp.z -= 5000;
if(c_trace (my_entity.x,temp,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS|IGNORE_SPRITES) <= 25)
{
phent_addvelcentral(my_entity,vector(0,0,250));
}
}
jumping=1;
}


This just seems like one of those things with a simple solution that I just dont know about yet.

Last edited by jfizer; 08/31/07 17:54.
Re: Typematic rate for key press or better option? [Re: jfizer] #151377
08/31/07 18:30
08/31/07 18:30
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
on_o = show_debug();

or in a loop

if(key_o)
{
show_debug();
while(key_o){wait(1);}
}

Re: Typematic rate for key press or better option? [Re: Shadow969] #151378
08/31/07 18:38
08/31/07 18:38
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
But wouldn't that freeze the game while the key is pressed?

Re: Typematic rate for key press or better option? [Re: jfizer] #151379
08/31/07 19:10
08/31/07 19:10
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
just make an own loop for that. but i advise using on_...

Re: Typematic rate for key press or better option? [Re: Shadow969] #151380
08/31/07 19:43
08/31/07 19:43
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
Quote:

just make an own loop for that. but i advise using on_...




adding on_o=show_debug(); before the main() function but after the show_debug() function does nothing. Putting it in the main() function but outside of the while(1) loop crashes the program when the key is pressed...

How would I add another loop outside of the main() while(1) one?

I know I must be missing somthing fundamental here.

Re: Typematic rate for key press or better option? [Re: jfizer] #151381
08/31/07 19:50
08/31/07 19:50
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
Odd... works fine if I use on_f1 but crashes if I use on_o

Re: Typematic rate for key press or better option? [Re: jfizer] #151382
09/01/07 04:48
09/01/07 04:48
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
add this somewhere
Code:
void use_debug_startup()//starter function, engine calls it on the startup
{
while(1)
{
if(key_o)
{
show_debug();
while(key_o){wait(1);}
}
wait(1);
}
}


not sure why on_o doesn't work, have you defined it within a function?

Re: Typematic rate for key press or better option? [Re: Shadow969] #151383
09/01/07 06:51
09/01/07 06:51
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
Quote:

not sure why on_o doesn't work, have you defined it within a function?




Nope. And its not just "dosn't work" it hard crashes (shrug).

Re: Typematic rate for key press or better option? [Re: jfizer] #151384
09/01/07 07:39
09/01/07 07:39
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
on_o = show_debug(); is wrong.. you have to assign the function pointer!: on_o = show_debug;

The reason is that the on_ events are function* pointer callbacks which are automatically executed. If you would like to assign several function depending on the gamestate, use a wrapper function which does the selection:

Code:
function on_o_event ()
{
if (gameState == gs_mainMenu) {
switchDebugMenu();
} else {
switchDebugDefault();
}
}

on_o = on_o_event;



Or something like this..

Re: Typematic rate for key press or better option? [Re: HeelX] #151385
09/01/07 18:38
09/01/07 18:38
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
Quote:

on_o = show_debug(); is wrong.. you have to assign the function pointer!: on_o = show_debug;




I'm aware of that, but for some reason I realy dont want to try and track down right now it just dosn't work. Using F1 is fine for now.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1