Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Keypresed question (https://forums.graalonline.com/forums/showthread.php?t=134264137)

greggiles 08-08-2011 08:59 AM

Keypresed question
 
Hello forums. This may be a dumb question to you, but i am still new to scripting.

I know you can do
Function on keyPressed(code, key)
{
If (key == "a"). Or whatever key

But what do i in the key check for right or left?

cbk1994 08-08-2011 09:03 AM

You should use

PHP Code:

function onKeyPressed(temp.code, temp.key, temp.scan) {
  if (
keydown(1)) {
    
player.chat = "Left!";
  } else if (
keydown(3)) {
    
player.chat = "Right!";
  }
} 

It's possible to check the key's code instead, but using keydown allows you to use the player's defined arrow keys.

There's a list of key numbers for keydown here.

Emera 08-08-2011 09:50 AM

Quote:

Originally Posted by cbk1994 (Post 1662475)
You should use

PHP Code:

function onKeyPressed(temp.code, temp.key, temp.scan) {
  if (
keydown(1)) {
    
player.chat = "Left!";
  } else if (
keydown(3)) {
    
player.chat = "Right!";
  }
} 

It's possible to check the key's code instead, but using keydown allows you to use the player's defined arrow keys.

There's a list of key numbers for keydown here.

I know this won't help you any more than what cbk told you, but I use this for all of my keycode needs. It is a simple way of finding out key codes by just inserting the desired key into a text box. Obviously you are talking about keydown not keydown2 but still, it might be useful.

blackbeltben 08-08-2011 08:41 PM

Can someone please explain the temp. thing. Im trying to learn. what is temp?

fowlplay4 08-08-2011 08:56 PM

Quote:

Originally Posted by blackbeltben (Post 1662527)
Can someone please explain the temp. thing. Im trying to learn. what is temp?

Probably should of created a thread to ask this question but here's an example.

PHP Code:

function onCreated() {
  
temp.a = 1;
  
example();
  echo(
temp.a); // echos "1"
}

function 
example() {
  
temp.a = 2;
  echo(
temp.a); // echos "2"
} 

Basically the value stays 'local' to the function it's in, and when the function is completed the value is discarded because it is no longer needed.

Placing the temp. prefix on your variable designates it as temporary. But that's the basic gist of it.


All times are GMT +2. The time now is 05:07 AM.

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