Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Holding a keydown... (https://forums.graalonline.com/forums/showthread.php?t=134262231)

devilsknite1 02-26-2011 07:12 AM

Holding a keydown...
 
When a keydown() is used in a timeout it can just be held and it will do the action for you. How do I eliminate this? Just in case I'm not clear since I'm half-delusional from sleep and am not even reading while I type, here's an example:

PHP Code:

//#CLIENTSIDE

function onTimeOut() {
  if ( 
keyDown) ) {
    
foobar;
  }
  
setTimer0.05 );


So, yeah. I just want to know how to make so the player must tap the key to get repeated use out of it.

DustyPorViva 02-26-2011 07:15 AM

You need to initiate the timeout first. The only setTimer you have is in the timeout itself, so nothing is telling it to actually start looping. Throw a setTimer in an onCreated.

devilsknite1 02-26-2011 07:17 AM

I know this, I'm just saying the context of it. Obviously, the script is much more than an uninitiated timeout with a keydown() in it :p

DustyPorViva 02-26-2011 07:20 AM

Oh, sorry I just read the script.

Anyways the only way to break the repeating function is to keep a flag on the key being hit. You can use onKeyPressed() but that has a repeat function based on default keyboard(after a second or so it'll start repeating).

PHP Code:

function onTimeout() {
  if (
keydown(5)) {
    if (
this.keydown5 == truedostuff();
    
this.keydown5 true;
  } else 
this.keydown5 false;



devilsknite1 02-26-2011 07:25 AM

I tried this and it didn't work... Although, when I did I combined the two line like this:

PHP Code:

if ( keyDown) && this.keydown5 == false ) { 

Would that have anything to do with it?

I also noticed every flag is set to true. Am I missing something there?

DustyPorViva 02-26-2011 07:29 AM

No you have to do it exactly as my post says because of the way the nested code works. If you do it like (keydown(5) && this.keydown5 == false) then it won't revert the this.keydown5 back to false since it requires not pressing S AND it being false.

devilsknite1 02-26-2011 07:33 AM

Now it doesn't work at all o_o

cbk1994 02-26-2011 07:36 AM

PHP Code:

function GraalControl.onKeyDown(codekeyscan) {
  
// if you care about matching default controls, use if (keydown) here
  
if (key == "a" && ! this.keyA) {
    
player.chat "tap!";
    
this.keyA true;
  }
}

function 
GraalControl.onKeyUp(codekeyscan) {
  if (
key == "a") {
    
this.keyA false;
  }


It's certainly possible to do via timeout, as Dusty instructed, but there's no reason to do so when it can be done using events.

Tricxta 02-26-2011 07:38 AM

damn I was just going to post when i saw chris did it >.<

devilsknite1 02-26-2011 07:50 AM

Ah, thanks to all of you. I knew there was a different way aside from timeouts.
Dusty, I got yours to work, I just entered it wrong. Although I had to change a few things around to make it work.
Chris, thank you for this method... Probably a bit more efficient and much cleaner than what I did.

DustyPorViva 02-26-2011 07:52 AM

Quote:

Originally Posted by devilsknite1 (Post 1633321)
Ah, thanks to all of you. I knew there was a different way aside from timeouts.
Dusty, I got yours to work, I just entered it wrong. Although I had to change a few things around to make it work.
Chris, thank you for this method... Probably a bit more efficient and much cleaner than what I did.

His does not account for default key layout though :( tsk tsk.

fowlplay4 02-26-2011 09:30 AM

I like the..

PHP Code:

//#CLIENTSIDE
function onKeyPressed() {
  
setTimer(0.05);
}

function 
onTimeout() {
  if (
keydown(5)) {
    
doStuff();
    
setTimer(0.05);
  }


way personally. Depends what you're doing in the end really.


All times are GMT +2. The time now is 11:34 AM.

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