Graal Forums

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

Shard_IceFire 10-13-2001 09:31 PM

Arrays...?
 
Hi!
I am a pretty good scripter, but one thing that I just skipped over when I was learning was arrays. I was wondering, exactly how do you use them? And what can they be used for?
Thanks.

ownerofbabylon 10-13-2001 09:34 PM

they are used for storing more than one thing in a variable. it would be like hearts(1) and hearts (2) but the variable would just be hearts but it breaks it up into parts

KJS 10-13-2001 09:36 PM

Re: Arrays...?
 
Quote:

Originally posted by Shard_IceFire
Hi!
I am a pretty good scripter, but one thing that I just skipped over when I was learning was arrays. I was wondering, exactly how do you use them? And what can they be used for?
Thanks.

well a basic array would be like
NPC Code:

if(created){
this.x={1,30,50,25};
this.y={5,20,18,30};
}
if(playertouchsme){
this.rnd=int(random(0,4));
x=this.x[this.rnd];
y=this.y[this.rnd];
}


ownerofbabylon 10-14-2001 04:45 AM

Re: Re: Arrays...?
 
Quote:

Originally posted by KJS


well a basic array would be like
NPC Code:

if(created){
this.x={1,30,50,25};
this.y={5,20,18,30};
}
if(playertouchsme){
this.rnd=int(random(0,4));
x=this.x[this.rnd];
y=this.y[this.rnd];
}


whats:

if(created){
this.x={1,30,50,25};
this.y={5,20,18,30};
}

for?

LiquidIce00 10-14-2001 07:20 AM

Re: Re: Re: Arrays...?
 
Quote:

Originally posted by ownerofbabylon


whats:

if(created){
this.x={1,30,50,25};
this.y={5,20,18,30};
}

for?

same thing as if you did
this.x[0]=1
this.x[1]=30
this.x[2]=50
this.x[3]=25

Xaviar 10-14-2001 07:52 AM

Re: Re: Re: Re: Arrays...?
 
Quote:

Originally posted by LiquidIce00


same thing as if you did
this.x[0]=1
this.x[1]=30
this.x[2]=50
this.x[3]=25

Maybe my mistake, but don't you need setarray this.x 4; in front of that?

btedji 10-14-2001 08:02 AM

Re: Re: Re: Re: Re: Arrays...?
 
Quote:

Originally posted by Xaviar


Maybe my mistake, but don't you need setarray this.x 4; in front of that?

yes

doing this.array={1,2,3,4}

is far more efficient

Xaviar 10-14-2001 08:08 AM

Re: Re: Re: Re: Re: Re: Arrays...?
 
Quote:

Originally posted by btedji


yes

doing this.array={1,2,3,4}

is far more efficient

'Tis generally what I do, unless I want the array to have a 'variable' length ;)

Shard_IceFire 10-16-2001 09:51 PM

=/ I still don't get why you would need them...

btedji 10-17-2001 03:49 AM

Quote:

Originally posted by Shard_IceFire
=/ I still don't get why you would need them...
say you have prices for different apples

you could do this:

this.appleprices={30,40,50,50}

then call it like this:

players[0].rupees-=this.appleprices[this.appletype];

which would be far more efficient than
having variables for each apple price and
would be easy to customize if you had at
the beginning of a script

Shard_IceFire 10-17-2001 07:11 AM

Quote:

Originally posted by btedji


say you have prices for different apples

you could do this:

this.appleprices={30,40,50,50}

then call it like this:

players[0].rupees-=this.appleprices[this.appletype];

which would be far more efficient than
having variables for each apple price and
would be easy to customize if you had at
the beginning of a script

I still don't quite get that....
rupees-=this.appleprices[this.appletype];
does it just choose one of the 'appleprices' numbers at random or something?


All times are GMT +2. The time now is 06:21 AM.

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