Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   keydown() (https://forums.graalonline.com/forums/showthread.php?t=40497)

Zigidias 11-21-2002 12:58 PM

keydown()
 
Is it jsut me or does keydown(#) finction not work very well?, it doesnt seem very reliable. Is there a better way?

Zigidias 11-21-2002 08:26 PM

so...

NPC Code:

if (keydown(9))
{
// commands
}



wont execute?
then how do i see if a button is pressed?

emortylone 11-21-2002 11:04 PM

You're assuming it as an action. Unlike keypressed, where it calls the action, keydown and keydown2 are best used in a timeout. Generally I do a clientside timeout of .05 and then do it. so:
NPC Code:

if (timeout)
{ if (keydown(0))
{ playery = playery-.1;}
timeout=0.05;
}


I can guarantee you that will work ;) Also, if you're using keydown2 it requires(key,true/false) I believe. So if keydown2(8,true) then it will perform the function. It AGAIN is NOT an action but a function as Kai calls them. To me, everything in an if statement is an action or a non-action. If you can use it like if (playerchats) || if (playertouchsme) kind of stuff, then it's an action. if (strequals(#a,Projectshifter)) however is not. That does not run by itself. hope it helps, enjoy.
---Shifter

Ningnong 11-22-2002 02:30 AM

Personally, I would use a timeout of .1 when using keydowns because .05 is too sensitive.

-Ningnong

Loriel 11-22-2002 02:43 AM

Quote:

Originally posted by Ningnong
Personally, I would use a timeout of .1 when using keydowns because .05 is too sensitive.

-Ningnong

Personally, I would use a timeout of 0.05 when using keydowns because 0.1 is too slow ;)

No reason to use 0.1 clientside.

Ningnong 11-22-2002 03:01 AM

I hate .05's because you have to just "touch" the key, and you find your self getting your tap right before it works (like its on and of with one normal press)..

Com013 11-22-2002 03:17 AM

Clientside I am most times using timeouts of 0.05 seconds.

The script should react immediatly and not lag behind a bit.
If you don't want the action to be repeated too often there are two ways.
The first way is to make sure that the key has been released before it has been repressed.
The second way is to count the time that has passed since the last action was triggered by the key.

osrs 11-22-2002 03:23 AM

I dont use keydown so much...
keydown2 is better.

Com013 11-22-2002 03:43 AM

Quote:

Originally posted by osrs
I dont use keydown so much...
keydown2 is better.

Not when you want to access the default keys. The user might change them and then you are checking for the wrong keys when using keydown2.

Zigidias 11-22-2002 06:12 AM

thanx to all of you, you helped out alot

emortylone 11-22-2002 06:18 AM

.05 may have it repeat at times, but then again when you do a GUI or something, .1 may be not sensitive enough, people often just tap and release. I'd say set a variable.
NPC Code:

if (created)
{ this.tap=0; timeout=.05;}
if (timeout)
{ if (keydown(0) && this.tap==0)
{ action(); this.tap=1;}
if (!keydown(0) && this.tap==1)
{ this.tap=0;}
timeout=.05;
}


That may be the best way.
---Shifter

CheeToS2 11-22-2002 07:09 AM

Quote:

Originally posted by Ningnong
I hate .05's because you have to just "touch" the key, and you find your self getting your tap right before it works (like its on and of with one normal press)..
make an array that checks if it was false first before performing the action (.05 seconds ago), then you won't have to worry about holding it down with the .1 stuff, and you won't have to worry about tapping with the plain .05 stuff :)

Com013 11-22-2002 10:40 PM

Ok, now the same thing has been said by me, Shifter and CheeToS2. Is there anybody else who wants to repeat it? ;)

Delteria_Free18 11-23-2002 01:19 AM

nah, I'd say 3 times is a charm....

Dach 11-24-2002 01:05 AM

meh, I'd rather do

NPC Code:

if (keypressed && keydown(blah)) {
action;
}



but if it needs to be in a timeout, then do what has been said three or four times now...

Knuckles 11-24-2002 01:34 AM

Quote:

Originally posted by Ningnong
I hate .05's because you have to just "touch" the key, and you find your self getting your tap right before it works (like its on and of with one normal press)..
you can use keypressed also.. but ning, you can also go like this if you wanna use timeout=0.05;
NPC Code:

if (timeout) {
if (keydown(0) && this.k0=0) {
this.k0=1;
playery-=.1;
} elseif (!keydown(0) && this.k0=1) {this.k0=0;}
timeout=0.05;
}



that would get rid of the "touch" and make it for everytime that you press it... or somthing like that =o

Com013 11-24-2002 01:59 AM

Quote:

Originally posted by Knuckles
you can also go like this if you wanna use timeout=0.05;
NPC Code:
[...]



that would get rid of the "touch" and make it for everytime that you press it... or somthing like that =o

The 4th repeat. Anybody else? ;)

Python523 11-24-2002 02:11 AM

Quote:

Originally posted by emortylone
.05 may have it repeat at times, but then again when you do a GUI or something, .1 may be not sensitive enough, people often just tap and release. I'd say set a variable.
NPC Code:

if (created)
{ this.tap=0; timeout=.05;}
if (timeout)
{ if (keydown(0) && this.tap==0)
{ action(); this.tap=1;}
if (!keydown(0) && this.tap==1)
{ this.tap=0;}
timeout=.05;
}


That may be the best way.
---Shifter

that could be a good way if your script wasn't inefficent


All times are GMT +2. The time now is 06:50 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.