Graal Forums

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

Dach 04-03-2003 05:39 AM

Multidimensional Strings
 
Now some of you know what these are, but here is a quick overview for those who don't;
Multidimensional strings are string arrays with more than one index (number assigned to a part of the string array). You may have seen the single dimension string arrays graal obviously has;
NPC Code:
 
setstring string,this,is,a,string,array;


but multidimensional arrays would have multiple entries for each of the entries in the above example. (like I said, quick)

Many of you have heard the rants about wanting these neat little things, but few have you know how to improvise them. I am going to show you a couple of different ways and explain the pros and cons of each one as best I can.

#1
altering the name of a string
You can emulate the properties of a multidimensional string array by using the names of the strings to your advantage;
NPC Code:

for (a=0;a<3;a++) {
for (b=0;b<3;b++) {
for (c=0;c<3;c++) {
setstring #v(a)_#v(b)_#v(c),#v(n);
n++;
}
}
}


-manual entering of indecies-
NPC Code:

setstring 0_0,1;
setstring 0_1,2;
setstring 1_0,3;
setstring 1_1,4;

(too much typing for the 3x3x3, so this is 2x2)
Will create a 3x3x3 string array with the indecies denoted in the name of the string. You can call each one the same way it is set
NPC Code:

#v(index1)_#v(index2)_#v(index3);


But of course this method will give you a new string for each entry, which while this may be easier to call, it takes up more memory (bad).

#2
altering name and making use of current string array function
You can shorten the number of strings created by using the built in string array system like so;
NPC Code:

for (a=0;a<3;a++) {
for (b=0;b<3;b++) {
for (c=0;c<3;c++) {
addstring #v(a)_#v(b),#v(n);
n++;
}
}
}


-manual entry-
NPC Code:

setstring 0,0,1;
setstring 0,1,2;
setstring 1,0,3;
setstring 1,1,4;

(again 2x2)
and you can call them like so
NPC Code:

#I(#v(index1)_#v(index2),index3);


this will shorten the number of strings to the dividend of the third index. It's a little more to type, but ohwell.

#3
integrating into current string arrays
this will put the whole string array into one string, it gets a little complicated in calling indecies, but it's worth it.
NPC Code:

setstring index,;
for (a=0;a<3;a++) {
setstring index1,;
for (b=0;b<3;b++) {
setstring index2,;
for (c=0;c<3;c++) {
addstring index2,#v(n);
n++;
}
addstring index1,#s(index2);
}
addstring index,#s(index1);
}


-manual entry-
NPC Code:

setstring string,"""0,1,2"",""3,4,5"",""6,7,8""","""9,10,11" ",""12,13,14"",""15,16,17""","""18,19,20"",""21,22 ,23"",""24,25,26""";

(note the placements of the "" )
and this is one of the ways to call a single entry;
NPC Code:

setstring string,#I(index,0);
setstring string1,#I(string,0);
setstring string2,#I(string1,1);
message #s(string2);



The third way can also be done with spaces and called using tokenize aswell but I've typed too much and need to get some sleep now. I hope this helps someone, and that I didn't make any mistakes... hehe

Dude6252000 04-03-2003 08:34 PM

Quote:

Originally posted by Onijustin_P2P
okay....riiiight.....i get it :rolleyes:
Was that post really necessary?

I've decided I'm going to start working with that stuff, though. I've been studying off of random scripts I find with those kinds of lights and etc, the multi-dimension ones, and I'm slowly learning how to do this stuff. Thanks for posting this. :O

Dach 04-04-2003 01:59 AM

Oh, boy, sorry about all the edits, I didn't have enough time to check everything while posting. All of it will work right, now.

Do take care to note the number of quotations around each entry, if you're not sure how many to put on, try using the for loop technique I did just to make sure (you might want to make sure, since I've tryed a couple of things and I have no idea whats going on).

Oh and Kai, your calling idea doesn't seem to work. It should, but doesn't. We should probably ask Stefan to make it work...


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

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