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
  #16  
Old 08-31-2011, 01:00 AM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
Quote:
Originally Posted by 0PiX0 View Post
It's unnecessary to initialize a var to be set to 0. When incrementing, checking the condition 'this.i >= 0' is unnecessary. Also, you have the keys swapped.

Astram, I would use the method Crow described. In the end it should look somewhat like this:
PHP Code:
function GraalControl.onKeyDown(temp.keycodetemp.keystringtemp.scancode) {
  switch (
keycode) {
    case 
219:  this.selectedid = (this.selectedid 1) % this.rights.size();  break;
    case 
220:  this.selectedid = (this.selectedid 1) % this.rights.size();  break;
    default:   return;
  }
  
player.chat this.rights[this.selectedid];

That returns as a NULL value, you know?
Reply With Quote
  #17  
Old 08-31-2011, 01:36 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
please stop using thiso throughout this script, you clearly have no idea what its intent and purpose is for. I am sure you are having all sorts of scoping issues by calling it since thiso probably refers to a null object or the player itself when you are doing that.

PHP Code:
//#CLIENTSIDE
function onCreated(){
  
this.rights = {"Drag""Boots""Blocks"};
  
this.selected 0;
}

function 
GraalControl.onKeyDown(temp.keycodetemp.keystringtemp.scancode){
  switch(
keycode){
    case 
219this.selected = (this.selected this.selected-1); break;
    case 
220this.selected = (this.selected >= this.rights.size() ? this.rights.size() -this.selected+1); break;
    default: return;
  }
  
player.chat this.rights[this.selected];

or

PHP Code:
//#CLIENTSIDE
function onCreated(){
  
this.rights = {"Drag""Boots""Blocks"};
  
this.selected 0;
}

function 
GraalControl.onKeyDown(temp.keycodetemp.keystringtemp.scancode){
  switch(
keycode){
    case 
219this.selected = (this.selected 1) % this.rights.size(); break;
    case 
220this.selected = (this.selected 1) % this.rights.size(); break;
    default: return;
  }
  
player.chat this.rights[this.selected];

Reply With Quote
  #18  
Old 08-31-2011, 10:25 PM
Astram Astram is offline
Era iPhone PR
Astram's Avatar
Join Date: Aug 2010
Posts: 324
Astram can only hope to improve
Send a message via AIM to Astram
By the way, what do
? and % mean in scripting? My scripting reference says:

? = tertiary operator (condition?true-case:false-case)
% = mod; a%b = a - int(a/b)*b;

I don't really understand that...
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #19  
Old 08-31-2011, 10:39 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
? is basically a shorthand for some types of if-statements.

PHP Code:
condition value_if_true value_if_false 
i.e.

PHP Code:
temp.var = "";

if (
3) {
  
temp.var = "x was more than 3";
} else {
  
temp.var = "x was less than 3";

is equivalent to

PHP Code:
temp.var = (3) ? "x was more than 3" "x was less than 3"
As for modulus, think of it like remainder.

PHP Code:
// 0
// 2
// 1
10 // 3 
__________________
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 12:01 PM.


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