Graal Forums

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

Mattehy 08-20-2009 08:09 PM

onKeyPressed()
 
PHP Code:

function onKeyPressed(code,key)
{
  if (
key == ???) 

Does anyone know the keys(vars) for the arrow keys im making a flute

Pelikano 08-20-2009 08:30 PM

You could get them with something like this:

PHP Code:

function onKeyPressed(codekey) {
  
player.chat code;



Mattehy 08-20-2009 08:31 PM

oh good idea xD

Deas_Voice 08-21-2009 04:08 PM

you could also use....
PHP Code:

function onKeyPressed(keycodekeyscancode) {
  
player.chat keycode SPC "/" SPC "/" SPC scancode;


to check all params'

DustyPorViva 08-21-2009 05:21 PM

PHP Code:

function onKeyPressed() {
  if (
keydown(0-3)) {
    
player.chat "arrow key pressed";
  }


keydown(int) can be used along with onKeyPressed() to detect default key configurations.

Pelikano 08-21-2009 05:51 PM

Quote:

Originally Posted by DustyPorViva (Post 1517154)
PHP Code:

function onKeyPressed() {
  if (
keydown(0-3)) {
    
player.chat "arrow key pressed";
  }


keydown(int) can be used along with onKeyPressed() to detect default key configurations.

doesn't give him the code... does it?

DustyPorViva 08-21-2009 05:57 PM

Quote:

Originally Posted by Pelikano (Post 1517162)
doesn't give him the code... does it?

Why would he need the code if he can detect it with the alternative I gave? Not to mention he was already given a script to detect the code... so yeah.

Gambet 08-21-2009 07:42 PM

Quote:

Originally Posted by DustyPorViva (Post 1517154)
PHP Code:

function onKeyPressed() {
  if (
keydown(0-3)) {
    
player.chat "arrow key pressed";
  }


keydown(int) can be used along with onKeyPressed() to detect default key configurations.


That's a bit vague for someone that might not be familiar with loops since they wouldn't realize that they would benefit from using one in this case:

PHP Code:

function onKeyPressed() {
  for (
temp.key 0temp.key 4temp.key++) {
    if (
keydown(key)) {
      
player.chat "directional key pressed";
    }
  }



Stuff like this has been posted before, possibly in multiple threads, people should really use the search function, they would get answers to their questions much faster.


EDIT: It's probably better to say 'directional key pressed' instead of 'arrow key pressed' since that would imply that the script would only trigger when you press an arrow key, when in fact it would trigger whenever you pressed any of the directional keys that you have set in your F3 options.

DustyPorViva 08-21-2009 09:39 PM

Quote:

Originally Posted by Gambet (Post 1517188)
That's a bit vague for someone that might not be familiar with loops since they wouldn't realize that they would benefit from using one in this case:

PHP Code:

function onKeyPressed() {
  for (
temp.key 0temp.key 4temp.key++) {
    if (
keydown(key)) {
      
player.chat "directional key pressed";
    }
  }



Stuff like this has been posted before, possibly in multiple threads, people should really use the search function, they would get answers to their questions much faster.


EDIT: It's probably better to say 'directional key pressed' instead of 'arrow key pressed' since that would imply that the script would only trigger when you press an arrow key, when in fact it would trigger whenever you pressed any of the directional keys that you have set in your F3 options.

Eh, I was more providing the values he could use(0-3) rather than implying he should loop... which he should.

As for arrows vs directional... probably, but it should always be applied to the customization of the player. If the player chooses to use WASD as their directional keys, this should also apply to whatever GUI's the player is using, so really directional translates into arrow as the player customizes them to basically be such(even if they're regular keys instead of the arrow keys). Developers need to keep that in mind.

cbk1994 08-21-2009 09:50 PM

It would be better if Stefan would provide a variable for which keys are used for movement/other stuff.

It's silly and redundant to have an event that passes paramaters, only to then have to call another function to see if a key is pressed, but I guess that's Graal.

Pelikano 08-21-2009 10:25 PM

Quote:

Originally Posted by cbk1994 (Post 1517228)
It would be better if Stefan would provide a variable for which keys are used for movement/other stuff.

It's silly and redundant to have an event that passes paramaters, only to then have to call another function to see if a key is pressed, but I guess that's Graal.

I only read that part, but it won't happen ;)

xXziroXx 08-21-2009 10:42 PM

Quote:

Originally Posted by Pelikano (Post 1517253)
I only read that part, but it won't happen ;)

I only read "Pelikano" on the left side of my screen, then realized the following text wouldn't be worth paying attention to.

Mattehy 08-22-2009 01:38 AM

Found Out The arrowkeys xD yesterday night its 38-40 xD

Switch 08-22-2009 03:23 AM

Quote:

Originally Posted by mattehy (Post 1517348)
found out the arrowkeys xd yesterday night its 38-40 xd

37-40 using the first param of onKeyPressed()
0-3 using keydown()

Pelikano 08-22-2009 11:14 AM

Quote:

Originally Posted by xXziroXx (Post 1517259)
I only read "Pelikano" on the left side of my screen, then realized the following text wouldn't be worth paying attention to.

Yet you read and answered to it? aww c'mon use some sense, please.


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

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