![]() |
Can anyone shed array of hope?
Bad pun, yes, I know, but that's not the point. :D
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. |
You proablly will benifeit from using string lists besides arrays if you want to store text.
|
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: Then the last index in the array will be 5. 2) To change something in an array, just use: NPC Code: 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: Have I missed anything (besides string arrays)? |
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. |
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 |
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) |
| All times are GMT +2. The time now is 08:23 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.