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 02-19-2003, 08:00 AM
Marukamu Marukamu is offline
Registered User
Join Date: Feb 2003
Posts: 4
Marukamu is on a distinguished road
Question Can anyone shed array of hope?

Bad pun, yes, I know, but that's not the point.

I've used arrays before in other programming languages, and the array seems to differ between languages. What I want to know is how arrays are used in Graal ( the command panel is not much help... ), and are they saved in any way like flags are?

What I am trying to do is use an NPCW to store certain settings in an array, and when necesary, display them in a GUI, and the data I want to store may not always be the same.
__________________
[ BOOGA ]
Reply With Quote
  #2  
Old 02-19-2003, 09:21 AM
tlf288 tlf288 is offline
Registered User
tlf288's Avatar
Join Date: Nov 2001
Location: new account: Trevor
Posts: 0
tlf288 is on a distinguished road
Send a message via AIM to tlf288 Send a message via Yahoo to tlf288
You proablly will benifeit from using string lists besides arrays if you want to store text.
__________________
new account: Trevor
Reply With Quote
  #3  
Old 02-19-2003, 09:28 AM
screen_name screen_name is offline
is watching you
Join Date: Mar 2002
Location: The 3rd Dimension
Posts: 2,160
screen_name is on a distinguished road
Send a message via AIM to screen_name Send a message via MSN to screen_name
CREATING ARRAYS
1) setarray name,length;
Will create a new array with the specified length which will be identified with the specified name.

2) arrayname = {0,0,..};
Same as above, but you can specify what will be in the array. (e.g. settings = {1,4,0,1,1,3}

ARRAY INDEXES
1) You must first create an array before you can access it. To access an array, then use "arrayname[#]" where # is the index you want to access. Also, indexes start at 0. So if you use:
NPC Code:

setarray settings,6;


Then the last index in the array will be 5.

2) To change something in an array, just use:
NPC Code:

name[i] = #;


name: The name of the array you wish to access
i: The index in which you want to change the value of
#: The value you want to set the accessed array index to
(Note: Regular arrays can only hold variables.)

3) If you want access something from an array, but not change it, just use something such as:
NPC Code:

if (playerchats && strequals(#c,show hp)) {
setplayerprop #c, #v(attributes[2]);
}




Have I missed anything (besides string arrays)?
__________________
[signature]insert here[/signature]
Reply With Quote
  #4  
Old 02-19-2003, 09:35 AM
PrinceDark PrinceDark is offline
Criminal X
PrinceDark's Avatar
Join Date: Feb 2003
Location: Miami, Florida
Posts: 662
PrinceDark will become famous soon enough
String lists is probably want you want to use.

sarraylen(str)
#I(list,text)
addstring list,text
insertstring list,text,index

There's a few other commands they you will find useful listed in the newfeatures text file.
__________________
- Criminal X: certified nut case
Reply With Quote
  #5  
Old 02-19-2003, 06:58 PM
thebluedagger thebluedagger is offline
Banned
Join Date: Feb 2003
Posts: 12
thebluedagger is on a distinguished road
If you've ever done C++ then it is similar. You can't use an array until it has been created. Therefore setarray <variable_name>,length; will create the var array, or this.var={0,1,2,3};
But I don't really think of strings as using arrays, as it is basically one string with quotations and commas
Addstring <string name>,<value>; is a common use, it adds it to the end. Replace string, insertstring, etc. are in commands.rtf file. To access it you use #I. #I(string,position)
---Shifter
Reply With Quote
  #6  
Old 02-20-2003, 01:56 AM
Falados Falados is offline
Cucumber NPC
Falados's Avatar
Join Date: Jan 2003
Posts: 141
Falados is on a distinguished road
Send a message via ICQ to Falados Send a message via AIM to Falados
Graal C++ will be better for datastorage, but in the mean time, I have to explain that GScript Variables cannot be strings... Strings are seperate.

Basically an array of string values is a string, delimited by commas or spaces (quotes will group strings, so you can include commas and spaces, eg string1=cat,dog,chicken,Super Cow; would be a string array of 5 strings, where as string2="cat,dog",chicken,"Super Cow"; would be 3)

other than that arrays are pretty much the same as C++, they just dont have to be declared, and they can be resized with setarray.

so

setarray array,3;
array[0] = 1;
array[1] = 2;
array[2] = 3;

and

array={1,2,3};

are both perfectly legal, although the latter is prefered (the first one resembles VB, and VB is posible the worst language X_X)
__________________

subliminal message: 1+1=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 03:48 AM.


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