Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-14-2008, 03:22 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
keydown2

I'm using keydown2 for several things on Utopia. One for guns system, one for melee.

Gun system checks 's', melee checks 'n'.

After a while (for some reason it seems to do this more on Macintosh computer, or when idling), the checks just stop working. Reconnecting does not help. You have to close Graal and open it back up.

This is what we have for one of them:

PHP Code:
  if ( keydown2getkeycode"s" ), false ) || keydown2getkeycode"n" ), false ) ) 
Funny thing is that when "S" fails, "N" fails.

Like I said, it might not happen more on Macs, but it seems to me like it. I know it DOES happen on Windows though.

What am I doing wrong? Is it a glitch with something else? Thanks!
__________________
Reply With Quote
  #2  
Old 02-14-2008, 09:54 AM
xAndrewx xAndrewx is offline
Registered User
xAndrewx's Avatar
Join Date: Sep 2004
Posts: 5,260
xAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud ofxAndrewx has much to be proud of
You'd need that in a timeout. Is it in one?

You're also checking that "S" and "N" are not pressed in that example.
__________________
Reply With Quote
  #3  
Old 02-14-2008, 02:54 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by xAndrewx View Post
You're also checking that "S" and "N" are not pressed in that example.
Not really. Extract from the wiki:

HTML Code:
keydown2( keycode,ignorecase)   checks if a key has been pressed (ignorecase must be 
                                    false to check for shift,ctrl,alt)
Reply With Quote
  #4  
Old 02-14-2008, 08:09 PM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
I would make sure that is in a timeout (I think you have it in one already, though). Also, I would set the second parameter to 'true' because you want it to ignore the case. It fails when players press capital S and N.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #5  
Old 02-14-2008, 11:45 PM
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
Thanks everyone, but I've already tried all of these.

It's completely unrelated to capitalization -- we have tried many things. All the keydown2 events on the server (for the player) just die, even on different scripts.

Like I said, unrelated to caps lock, etc at all.

YES, it is in a timeout, Andrew! I'm not that dumb.

I'm sure it's some little thing I've missed -- I'll recheck tonight ... I just can't understand why they all would stop working at the same time IN DIFFERENT SCRIPTS.
__________________
Reply With Quote
  #6  
Old 02-14-2008, 11:50 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by cbkbud View Post
YES, it is in a timeout
Why are you using a timeout though?

PHP Code:
function onKeyPressed(codekey) {
  switch (
lowercase(key)) {
    case 
"s":
      
player.chat "S";
    break;
    case 
"n":
      
player.chat "N";
    break;
  }

__________________
Reply With Quote
  #7  
Old 02-14-2008, 11:56 PM
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
Quote:
Originally Posted by Chompy View Post
Why are you using a timeout though?

PHP Code:
function onKeyPressed(codekey) {
  switch (
lowercase(key)) {
    case 
"s":
      
player.chat "S";
    break;
    case 
"n":
      
player.chat "N";
    break;
  }

Because you can't use that to detect when a key is held down.
__________________
Reply With Quote
  #8  
Old 02-15-2008, 12:01 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by cbkbud View Post
Because you can't use that to detect when a key is held down.
well, you kind of can:

PHP Code:
//#CLIENTSIDE
function onCreated()
  
setTimer(0.1);
function 
onTimeout() {
  
// or whatever to detect if it's not held down
  
if (!keydown(5)) this.canhit true;
  
setTimer(0.1);  
}
function 
onKeyPressed(codekey) {
  switch (
lowercase(key)) {
    case 
"s":
      if (
this.canhit) {
        
player.chat "s";
        
this.canhit false;
      }
    break;
  }

__________________
Reply With Quote
  #9  
Old 02-15-2008, 12:30 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
Quote:
Originally Posted by Chompy View Post
well, you kind of can:

PHP Code:
//#CLIENTSIDE
function onCreated()
  
setTimer(0.1);
function 
onTimeout() {
  
// or whatever to detect if it's not held down
  
if (!keydown(5)) this.canhit true;
  
setTimer(0.1);  
}
function 
onKeyPressed(codekey) {
  switch (
lowercase(key)) {
    case 
"s":
      if (
this.canhit) {
        
player.chat "s";
        
this.canhit false;
      }
    break;
  }

That would never work. x.x
If we're having a timeout anyway, why not just use keydown2?
Also should use key.lower() instead of lowercase( key )
__________________
Reply With Quote
  #10  
Old 02-15-2008, 10:54 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by cbkbud View Post
Because you can't use that to detect when a key is held down.
PHP Code:
function GraalControl.onKeyDown(keycodekeystringscancode) {
}
function 
GraalControl.onKeyUp(keycodekeystringscancode) {

Would that not do it?
__________________
Reply With Quote
  #11  
Old 02-15-2008, 01:51 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
I have the same keydown2 setup on AEON, and it works fine... I just have the second param set to 'true'.

Also, as a side note:
When you are using the second param for onKeyPressed, you do not need to put capitalization into account :P.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #12  
Old 02-15-2008, 03:10 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
TGraalVar.lower(), converts the string variable to lowercase. upper() does the opposite.
__________________
Reply With Quote
  #13  
Old 02-15-2008, 11:17 PM
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
When I originally tried it it turned out to be very buggy. I'll try it out again, thanks.
__________________
Reply With Quote
  #14  
Old 02-15-2008, 11:34 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
Quote:
Originally Posted by cbkbud View Post
When I originally tried it it turned out to be very buggy. I'll try it out again, thanks.
That method would only work when you have the GraalControl selected; meaning that you're able to move your player and such.

Another thing, I noticed that onKeyPressed() does not detect Ctrl+Key while GuiControl.onKeyDown() does.
__________________
Reply With Quote
  #15  
Old 02-16-2008, 12:19 AM
pokeSMOT pokeSMOT is offline
Registered User
Join Date: Jun 2006
Posts: 35
pokeSMOT is on a distinguished road
Newbie Scripter seeks line-by-line breakdown

//#CLIENTSIDE
function onCreated()
Why onCreated() and not just Created()? What does "on" do?
setTimer(0.1);
What is the timer used for? and if it's declared within a function, why not just call the function for later use?
function onTimeout() {
What is the difference between "setTimer" and "onTimeout"?
// or whatever to detect if it's not held down
if (!keydown(5)) this.canhit = true;
Does this mean if whatever key '5' represents, pressing the opposite will activate "this.canhit = true;"? And what does that part mean?
setTimer(0.1);
Couldn't the whole function be called?
}
function onKeyPressed(code, key) {
Are "code" and "key" some sort of preset parameters or something? What do those mean? Cause I don't see them defined anywhere..
switch (lowercase(key)) {
Is capslock relevant here, or is this for something else?
case "s":
I remember case's from C++, but the next part is what troubles me..
if (this.canhit) {
Is this still asking if while it is true?
player.chat = "s";
So if "this.canhit" was set to true, then it makes the player say "s"? But then how is this.canhit even determinded? By pressing any key other than '5'?
this.canhit = false;
And I'm guessing that absolutely nothing happens if this.canhit is false, cause there's nothing after it except closing brackets
}
break;
And this simply halts the script? no?
}
}

Sorry to whomever takes the time out to read through and answer this post, but I'm really trying to learn this stuff. I find gs2 quite fascinating.
Reply With Quote
  #16  
Old 02-16-2008, 03:33 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
I'll try my best to explain it in a way you can understand. Let me know if you still have a question.

Quote:
Originally Posted by pokeSMOT View Post
//#CLIENTSIDE
function onCreated()
Why onCreated() and not just Created()? What does "on" do?
setTimer(0.1);
'created' is the name of an event. In GS2, when an event happens, the function onEVENTNAMEHERE() is called (if the function is defined).

Quote:
Originally Posted by pokeSMOT View Post
What is the timer used for? and if it's declared within a function, why not just call the function for later use?
function onTimeout() {
What is the difference between "setTimer" and "onTimeout"?
// or whatever to detect if it's not held down
if (!keydown(5)) this.canhit = true;
The difference between setTimer() and onTimeOut() is that using onTimeOut() starts the timeout immediately, while setTimer() lets you define how long you want the script to wait before calling onTimeOut(). In Chompy's example he probably should have used onTimeOut() instead of the first setTimer().

Quote:
Originally Posted by pokeSMOT View Post
Does this mean if whatever key '5' represents, pressing the opposite will activate "this.canhit = true;"?
You're very warm. As long key '5' (which is the S key) is not pressed, then this.canhit will be set to true. So, even if nothing is being pushed, this.canhit will be set to true.

Quote:
Originally Posted by pokeSMOT View Post
And what does that part mean?
setTimer(0.1);
Couldn't the whole function be called?
In this case, you want a little delay between the next time onTimeOut() is called. You could call onTimeOut() directly, but this will result in it being called too many times too quickly (LAG!).

Quote:
Originally Posted by pokeSMOT View Post
function onKeyPressed(code, key) {
Are "code" and "key" some sort of preset parameters or something? What do those mean? Cause I don't see them defined anywhere..
keypressed is an event that passes two parameters when it is called. In GS2, you can give the parameters temporary variables. In this case, Chompy chose to name the variables 'code' and key'. If he didn't name the variables, he would have to access them using params[0] and params[1].

Quote:
Originally Posted by pokeSMOT View Post
switch (lowercase(key)) {
Is capslock relevant here, or is this for something else?
You actually do not need to account for caps in this example.

Quote:
Originally Posted by pokeSMOT View Post
And this simply halts the script? no?
In switch statements, you need the break at the end of each case to prevent the script from going to the next case. In this example, it isn't really needed as there are no other cases. It's alright to include the break though, so in case you do add to the switch statement later, you won't have to worry about forgetting to add the break.
__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.

Last edited by napo_p2p; 02-16-2008 at 08:23 AM..
Reply With Quote
  #17  
Old 02-16-2008, 04:55 AM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
onKeyPressed() is actually passing three parameters: keymodifier, keystring, and scancode.
__________________
Reply With Quote
  #18  
Old 02-16-2008, 01:06 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Err, I just remembered why I lower cased the key.. I made the battle system on symp.. err 5-6 months ago? Anyways, I thought that the event would return "s" and "S". So using
PHP Code:
switch(key) {
  case 
"s":
  break;
  case 
"S":
  break;

Would be unnecesary so I just lowercased the key so I would only need the "s" part..

But back then I didn't check if it returned "s" and "S", I just added it because I thought the event would return "s" and "S"..
__________________
Reply With Quote
  #19  
Old 02-16-2008, 01:47 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Chompy View Post
Err, I just remembered why I lower cased the key.. I made the battle system on symp.. err 5-6 months ago? Anyways, I thought that the event would return "s" and "S". So using
PHP Code:
switch(key) {
  case 
"s":
  break;
  case 
"S":
  break;

Would be unnecesary so I just lowercased the key so I would only need the "s" part..

But back then I didn't check if it returned "s" and "S", I just added it because I thought the event would return "s" and "S"..
If it returns "s" and "S", doing the following is probably easier:

PHP Code:
switch (key) {
  case 
"s":
  case 
"S":
    
//stuff
  
break;

Reply With Quote
  #20  
Old 02-16-2008, 04:26 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Crow View Post
If it returns "s" and "S", doing the following is probably easier:

PHP Code:
switch (key) {
  case 
"s":
  case 
"S":
    
//stuff
  
break;

Hehe.
__________________
Do it with a DON!
Reply With Quote
  #21  
Old 02-16-2008, 09:49 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by zokemon View Post
Didnt even read that. Nice one

I basically always use switch, because i think it reads better.



Edit: Reading through that thread a little more, it looks like I did read it. But I cant remember :/
Reply With Quote
  #22  
Old 02-16-2008, 05:23 PM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
I usually don't use switch/case statements for my onKeyPressed() events, since I usually just have one key press per script that matters, so I just generally go with if (lowercase(key) == whatever)...
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
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 09:12 PM.


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