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 04-16-2008, 02:55 AM
Frankie Frankie is offline
xChugxLifex
Frankie's Avatar
Join Date: Feb 2008
Location: New York
Posts: 1,610
Frankie is a jewel in the roughFrankie is a jewel in the rough
Send a message via AIM to Frankie Send a message via MSN to Frankie
getting an index

I'm having a little trouble here.

I'm making a bounty system, the account and the amount of money for that bounty will be placed in an array like this:

this.bounty = {{"Frankie", 2000}, {"TSAdmin", 1500}};

when a player dies I want to check if they are in the list, but I can't do that because I'm having trouble checking the index.

function onCreated()
{
this.array = {{"Frankie", 2000}, {"TSAdmin", 1500}};
this.getIndex = this.array.index("Frankie");
sendtorc(this.getIndex);
}

returns -1.

I need it to return 0 this way I can do:

this.moneyAmount = this.array[this.getIndex][1];

there's something I'm missing but TSA and I can't figure it out.
__________________
*Sum41Freeeeek
*Frankie
Reply With Quote
  #2  
Old 04-16-2008, 03:08 AM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Try maybe:
PHP Code:
temp.array = {{"Frankie","TSAdmin"},{2000,1500}};
temp.ind temp.array[0].index("Frankie");
echo(
temp.ind);
echo(
temp.array[1][temp.ind]); 
The way you're doing it will not work; you can loop through the elements to find the right index, like so:
PHP Code:
temp.array = {{"Frankie",2000},{"TSAdmin",1500}};
temp.temp.array.size();
for (
temp.i=0;temp.i<temp.l;temp.i++)
  if (
temp.array[temp.i][0] == "Frankie") {
    echo(
temp.i);
    break;
  }
echo(
temp.array[temp.i][1]); 
By my best estimates (read: guess), the former is ~2.5x faster.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #3  
Old 04-16-2008, 03:11 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
You can't get the index of a subaray in an array without a loop.

PHP Code:
// ...

this.array = {{"Frankie"2000}, {"TSAdmin"1500}};
this.getIndex index2(this.array, "Frankie");
echo(
this.array[this.getIndex][0SPC "found!");

// ...

function index2(array, acc)
{
  for (
temp.arg: array) {
    if (
temp.arg[0] == acc) return array.index(temp.arg);
  }
  return -
1;

EDIT: Bah, Pfa beat me too it!
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #4  
Old 04-16-2008, 09:41 AM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
You're probably better off just storing them all in variables like:
PHP Code:
this.bountylist.Frankie 2000;
this.bountylist.TSAdmin 1500;

temp.foo this.bountylist.(@ player.account);
echo(
"My bounty is " foo); 
You can also transfer the list by use of:
PHP Code:
this.bountyarray this.bountylist.savevarstoarray(true); 
And:

PHP Code:
this.bountylist.loadvarsfromarray(this.bountyarray); 
__________________
Do it with a DON!
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 08:16 AM.


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