![]() |
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:
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! |
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. |
Quote:
HTML Code:
keydown2( keycode,ignorecase) checks if a key has been pressed (ignorecase must be |
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.
|
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. |
Quote:
PHP Code:
|
Quote:
|
Quote:
PHP Code:
|
Quote:
If we're having a timeout anyway, why not just use keydown2? Also should use key.lower() instead of lowercase( key ) |
Quote:
**) Well, onKeyPressed() will always be called, was just a thought tho.. ***) explain :) |
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. |
TGraalVar.lower(), converts the string variable to lowercase. upper() does the opposite.
|
Quote:
onKeyPressed() is called at first, then repeatedly after like a second. lowercase( ) is GS1 existing for compatibility. str.lower() is gs2. |
Quote:
PHP Code:
|
When I originally tried it it turned out to be very buggy. I'll try it out again, thanks.
|
Quote:
Another thing, I noticed that onKeyPressed() does not detect Ctrl+Key while GuiControl.onKeyDown() does. |
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. |
I'll try my best to explain it in a way you can understand. Let me know if you still have a question.
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
|
onKeyPressed() is actually passing three parameters: keymodifier, keystring, and scancode.
|
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:
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".. |
Quote:
PHP Code:
|
Quote:
|
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:
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 :/ |
| All times are GMT +2. The time now is 10:08 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.