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
  #1  
Old 08-29-2011, 07:19 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
Array help

This wont select the next variable in thiso.rights.
thiso.rights = Stick,Unstick,Jail,Stealth
can someone help me get this to work?
PHP Code:
function onKeyPressed(codekeyscancode) {
  for (
temp.0temp.thiso.rights.size(); temp.++) {
    
//[ 219
    //] 221
    //\ = 220,\,43
    
if (code == 219) {
      
//[
      
if (this.selected => thiso.rights[0]) {
        
this.selectedid temp.i;
        
this.selected thiso.rights[(@this.selectedid 1)];
        
UpdateText(this.selected);
      }
    }
    if (
code == 220) {
      
//\
      
if (this.selected =< thiso.rights.size() - 1) {
        
this.selectedid temp.i;
        
this.selected thiso.rights[(@this.selectedid 1)];
        
UpdateText(this.selected);
      }
    }
  }

__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #2  
Old 08-29-2011, 07:28 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Why are you using a thiso prefix there? Should work with a regular this prefix.
__________________
Reply With Quote
  #3  
Old 08-29-2011, 08: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
Quote:
Originally Posted by Crow View Post
Why are you using a thiso prefix there? Should work with a regular this prefix.
In a different part of the script im using thiso. because well I need it
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #4  
Old 08-29-2011, 08:46 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
But you do not need it in this case. You only need that particular prefix if you want to reference to the NPC the code is executed in while being in another NPC's scope, like inside some of this stuff:
PHP Code:
with (npc) {
  
// boo

__________________
Reply With Quote
  #5  
Old 08-29-2011, 11:01 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
Quote:
Originally Posted by Crow View Post
But you do not need it in this case. You only need that particular prefix if you want to reference to the NPC the code is executed in while being in another NPC's scope, like inside some of this stuff:
PHP Code:
with (npc) {
  
// boo

Would that mess up the script like the problem im having...
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #6  
Old 08-29-2011, 11:03 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Astram View Post
Would that mess up the script like the problem im having...
Just try using a this prefix instead of the thiso one.
__________________
Reply With Quote
  #7  
Old 08-29-2011, 11:07 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
Quote:
Originally Posted by Crow View Post
Just try using a this prefix instead of the thiso one.
Alright, gotcha, but do you know why the array isnt displaying anything besides this.rights[0]
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #8  
Old 08-29-2011, 11:10 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Astram View Post
Alright, gotcha, but do you know why the array isnt displaying anything besides this.rights[0]
Dunno. I was being lazy and assumed that the wrong prefix was the only problem. Let me take a closer look..

Edit: What do you want to do, anyway? Your conditions seem strange; you also got your operators the wrong way (=> and =< instead of >= and <=, but I'm not sure if that even matters). Also, you're converting an integer to a string for your array index here:
PHP Code:
this.selected thiso.rights[(@this.selectedid 1)]; 
Which isn't even necessary. This should do:
PHP Code:
this.selected this.rights[this.selectedid 1]; 
__________________
Reply With Quote
  #9  
Old 08-29-2011, 11:32 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
I'm trying to make it so that you can change which variable in the array you are showing, by pressing [ and \. Once like first it will say Stick, then you press \. And it would do UpdateText(); to say Unstick, then Jail, then Stealth. But it shouldn't go any higher then the array size, and the array minimum.
__________________
-Toad
The worlds biggest Toad fan...
Era iPhone FTW!


Reply With Quote
  #10  
Old 08-29-2011, 11:39 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
You could use the modulo operator for this one.
PHP Code:
this.selectedid = (this.selectedid 1) % this.rights.size(); 
Should also work for "scrolling" in the other direction. No need for a loop either. Just check the key code and do that.
__________________
Reply With Quote
  #11  
Old 08-29-2011, 11:45 PM
gaben gaben is offline
uhh no
gaben's Avatar
Join Date: Aug 2011
Posts: 47
gaben is an unknown quantity at this point
I don't even know why you're looping it strangely in the first place, but you wrote temp.i < thiso.rights.size() instead of temp.i <= thiso.rights.size()? You'd be excluding one less array item.

In general though, there really isn't anything to 'fix' persay if we don't even know how you store your array vars (this.orights? too vague) or what you're really trying to do. Apparently you want to change the array with '[' or / yet nothing is indicating any keypresses besides onKeyPressed() which you didn't utilize properly anyway. Wat?

I guess you want to increment your array [] selectors, so why not just increment temp.i and de-increment them on '[' & / keypresses?
__________________
Quote:
Originally Posted by iBeatz View Post
Who came up with this Cheat Engine? The more I read about, the more ingenious the whole thing sounds.
Quote:
Originally Posted by Unixmad
This forums is going worst each day.
Quote:
Originally Posted by ff7chocoboknight View Post
You sure are taking your time leaving, furry.
Quote:
Originally Posted by [email protected] View Post
are u old enough 2 even play Graal little girl???
Reply With Quote
  #12  
Old 08-30-2011, 12:05 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Quote:
Originally Posted by gaben View Post
I don't even know why you're looping it strangely in the first place, but you wrote temp.i < thiso.rights.size() instead of temp.i <= thiso.rights.size()? You'd be excluding one less array item.
No, although his script doesn't require a loop, he is looping it correctly. In arrays, the first element's index is 0, and the last element's index is array.size() - 1.
Reply With Quote
  #13  
Old 08-30-2011, 12:24 AM
gaben gaben is offline
uhh no
gaben's Avatar
Join Date: Aug 2011
Posts: 47
gaben is an unknown quantity at this point
Quote:
Originally Posted by 0PiX0 View Post
No, although his script doesn't require a loop, he is looping it correctly. In arrays, the first element's index is 0, and the last element's index is array.size() - 1.
I didn't say he was looping it incorrectly, I just said it was rather strange compared to what he wanted to accomplish.

Anyway, it'd be much easier to just increment like this and perform some checks for this.i or whatever number he'll be using for the array [0] selector.

PHP Code:
//#CLIENTSIDE

function onCreated(){
  
this.0;
}

function 
onKeyPressed(codekey){
  if(
key == "[" && this.>= && this.3){
         
this.i++; // increment
         
player.chat this.i// print out for verification
  
}
  else if(
key == "/" && this.0){ // don't decrement 0 to -1!
        
this.i--;
        
player.chat this.i;
  }

Then I guess you'd do something like: thiso.rights[this.i] (selectors, 0,1,2,3).
__________________
Quote:
Originally Posted by iBeatz View Post
Who came up with this Cheat Engine? The more I read about, the more ingenious the whole thing sounds.
Quote:
Originally Posted by Unixmad
This forums is going worst each day.
Quote:
Originally Posted by ff7chocoboknight View Post
You sure are taking your time leaving, furry.
Quote:
Originally Posted by [email protected] View Post
are u old enough 2 even play Graal little girl???

Last edited by gaben; 08-30-2011 at 01:03 AM..
Reply With Quote
  #14  
Old 08-30-2011, 01:44 AM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Quote:
Originally Posted by gaben View Post
PHP Code:
function onCreated(){
  
this.0;
}

function 
onKeyPressed(codekey){
  if(
key == "[" && this.>= && this.3){
         
this.i++; // increment
         
player.chat this.i// print out for verification
  
}
  else if(
key == "/" && this.0){ // don't decrement 0 to -1!
        
this.i--;
        
player.chat this.i;
  }

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];

Reply With Quote
  #15  
Old 08-31-2011, 12:29 AM
gaben gaben is offline
uhh no
gaben's Avatar
Join Date: Aug 2011
Posts: 47
gaben 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];

wat?

PHP Code:
//#CLIENTSIDE

function onCreated(){
  
this.rights = {"Stick","Unstick","Jail","Stealth"};
}


function 
onKeyPressed(codekey){ 
  if(
key == "[" && this.3){ 
         
this.i++; // increment 
         
player.chat this.rights[this.i]; 
  } 
  else if(
key == "/" && this.0){ // don't decrement 0 to -1! 
        
this.i--; 
        
player.chat this.rights[this.i]; 
  } 

__________________
Quote:
Originally Posted by iBeatz View Post
Who came up with this Cheat Engine? The more I read about, the more ingenious the whole thing sounds.
Quote:
Originally Posted by Unixmad
This forums is going worst each day.
Quote:
Originally Posted by ff7chocoboknight View Post
You sure are taking your time leaving, furry.
Quote:
Originally Posted by [email protected] View Post
are u old enough 2 even play Graal little girl???

Last edited by gaben; 08-31-2011 at 02:15 AM..
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 04:26 AM.


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