Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-26-2011, 07:12 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
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.
Reply With Quote
  #2  
Old 02-26-2011, 07:15 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #3  
Old 02-26-2011, 07:17 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
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
Reply With Quote
  #4  
Old 02-26-2011, 07:20 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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;

Reply With Quote
  #5  
Old 02-26-2011, 07:25 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
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?
Reply With Quote
  #6  
Old 02-26-2011, 07:29 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #7  
Old 02-26-2011, 07:33 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
Now it doesn't work at all o_o
Reply With Quote
  #8  
Old 02-26-2011, 07:36 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #9  
Old 02-26-2011, 07:38 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
damn I was just going to post when i saw chris did it >.<
Reply With Quote
  #10  
Old 02-26-2011, 07:50 AM
devilsknite1 devilsknite1 is offline
C:
devilsknite1's Avatar
Join Date: Jul 2006
Location: Florida, USA
Posts: 269
devilsknite1 has a spectacular aura about
Send a message via AIM to devilsknite1 Send a message via MSN to devilsknite1 Send a message via Yahoo to devilsknite1
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.
Reply With Quote
  #11  
Old 02-26-2011, 07:52 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by devilsknite1 View Post
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.
Reply With Quote
  #12  
Old 02-26-2011, 09:30 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:32 PM.


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