Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-08-2011, 08:59 AM
greggiles greggiles is offline
Registered User
greggiles's Avatar
Join Date: Sep 2007
Posts: 149
greggiles has a spectacular aura about
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?
Reply With Quote
  #2  
Old 08-08-2011, 09:03 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
You should use

PHP Code:
function onKeyPressed(temp.codetemp.keytemp.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.
__________________
Reply With Quote
  #3  
Old 08-08-2011, 09:50 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Quote:
Originally Posted by cbk1994 View Post
You should use

PHP Code:
function onKeyPressed(temp.codetemp.keytemp.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.
__________________
Reply With Quote
  #4  
Old 08-08-2011, 08:41 PM
blackbeltben blackbeltben is offline
Registered User
Join Date: Aug 2011
Posts: 83
blackbeltben is on a distinguished road
Can someone please explain the temp. thing. Im trying to learn. what is temp?
Reply With Quote
  #5  
Old 08-08-2011, 08:56 PM
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
Quote:
Originally Posted by blackbeltben View Post
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.1;
  
example();
  echo(
temp.a); // echos "1"
}

function 
example() {
  
temp.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.
__________________
Quote:
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 05:24 PM.


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