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 05-15-2005, 01:32 AM
DarkShadows_Legend DarkShadows_Legend is offline
Cult of the Winky
DarkShadows_Legend's Avatar
Join Date: Apr 2003
Location: Florida
Posts: 614
DarkShadows_Legend is on a distinguished road
Send a message via AIM to DarkShadows_Legend
Question MultiDimensional Arrays

This is new to me and it looks weird. Will someone be kind enough to explain to me how they work and provide some basic examples. I just got GS2 on this world I'm developing and want to experiment with this stuff.

I have seen some scripts that have lines of code like ...
NPC Code:

myvar = {{{val}}, val2, val3};



I believe there is another way of creating them for GS2 that is like old GS1
Quote:
GS1 -> setarray myvar,length;
GS2 -> setarray(myvar,length); // not quite sure
How would a multidimensional array be set for GS2?

If anyone could explain this to me and provide a couple of examples I would be extremely greatful. Thanks
__________________
- Criminal X

"I rather be hated for being myself, than be liked for being what you like best. I go above the influence, not under." - Me
Reply With Quote
  #2  
Old 05-15-2005, 02:03 AM
Velox Cruentus Velox Cruentus is offline
Registered User
Velox Cruentus's Avatar
Join Date: Dec 2004
Location: Quebec, Canada
Posts: 465
Velox Cruentus is on a distinguished road
Send a message via ICQ to Velox Cruentus Send a message via AIM to Velox Cruentus
var = new[length];

var[x] = new[x];

Or:

var = {{x,y},{x,y}};

You can grab the variables by:

var[1][1];
__________________
In a world of change... Who'll you believe?
Reply With Quote
  #3  
Old 05-15-2005, 09:29 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by Velox Cruentus
var = new[length];
I think there's also a way to have the array be initialised as multi-dimensional. new[height,width]?
__________________
Reply With Quote
  #4  
Old 05-15-2005, 04:32 PM
Zero Hour Zero Hour is offline
Stiff Upper Lip
Zero Hour's Avatar
Join Date: Oct 2006
Location: Nova Scotia, Canada
Posts: 0
Zero Hour is on a distinguished road
Send a message via AIM to Zero Hour
What's advantages does a multidimensional array have? I cannot understand any use.
__________________
Reply With Quote
  #5  
Old 05-15-2005, 04:56 PM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
it's basically an easier to use string list, i think

normally when you want to create a structure like this

NPC Code:
item1
- sub info 1
- sub info 2
- sub info 3
item2
- sub info 1
- sub info 2
- sub info 3
item3
- sub info 1
- sub info 2
- sub info 3



you have to use a long string list:

NPC Code:
sub info 1,sub info 2, sub info 3, sub info 1,sub info 2, sub info 3, sub info 1,sub info 2, sub info 3



and use simple math to figure out where the info is (the index is i*n+3 for this example, where i is the item and n is the sub item)

with a multidimensional array, it's a little easier

NPC Code:
array = {{sub info 1,sub info 2, sub info 3},{sub info 1,sub info 2, sub info 3}, {sub info 1,sub info 2, sub info 3}}



you can access the items with:

array[i][n]
__________________

Reply With Quote
  #6  
Old 05-15-2005, 05:02 PM
Velox Cruentus Velox Cruentus is offline
Registered User
Velox Cruentus's Avatar
Join Date: Dec 2004
Location: Quebec, Canada
Posts: 465
Velox Cruentus is on a distinguished road
Send a message via ICQ to Velox Cruentus Send a message via AIM to Velox Cruentus
Now -- The utility can be a variety of things... First off, the arrays can now carry texts...
You can use it to create a background for easy access to the x and y coordinates, such as:

PHP Code:
  this.levelt := new[64,64];
  for (
0< (64*64); i++)
    
this.level[i%64][int(i/64)] = tiletype(i%64,int(i/64)); 
And then grab the variables by:
this.levelt[x][y]; Making it just a different way to bypass it, or store variables. This could be used to make minigames with tiles of your own set, were you create the blocking via tiles:
PHP Code:
this.var := {
 {
0,1,1,0,0,2,0},
 {
0,1,0,0,1,2,0},
 {
0,0,0,1,2,2,1}
}; 
Or... You can use it, in the case that I did in my Item System script:
PHP Code:
this.item := {{"Prop",var},{"Prop",var}}; 
It all depends on what you want to use it for.
__________________
In a world of change... Who'll you believe?
Reply With Quote
  #7  
Old 05-15-2005, 05:17 PM
Zero Hour Zero Hour is offline
Stiff Upper Lip
Zero Hour's Avatar
Join Date: Oct 2006
Location: Nova Scotia, Canada
Posts: 0
Zero Hour is on a distinguished road
Send a message via AIM to Zero Hour
Ah, I see
__________________
Reply With Quote
  #8  
Old 05-15-2005, 08:48 PM
PrinceDark PrinceDark is offline
Criminal X
PrinceDark's Avatar
Join Date: Feb 2003
Location: Miami, Florida
Posts: 662
PrinceDark will become famous soon enough
This is a very nice addition. Saves me the trouble of creating so many separate arrays/string lists. Thanks all.
__________________
- Criminal X: certified nut case
Reply With Quote
  #9  
Old 05-16-2005, 05:54 AM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
Quote:
Originally Posted by Velox Cruentus
PHP Code:
  this.levelt := new[64,64];
  for (
0< (64*64); i++)
    
this.level[i%64][int(i/64)] = tiletype(i%64,int(i/64)); 
loading an entire level into a string list lagged the server a LOT when I did it before, and the new multidimensional (string) arrays seem to be a lot like string lists in disguise....
__________________

Reply With Quote
  #10  
Old 05-16-2005, 01:44 PM
Velox Cruentus Velox Cruentus is offline
Registered User
Velox Cruentus's Avatar
Join Date: Dec 2004
Location: Quebec, Canada
Posts: 465
Velox Cruentus is on a distinguished road
Send a message via ICQ to Velox Cruentus Send a message via AIM to Velox Cruentus
Try clientside. It was an example.

It is a string list... Easier to access them (Infact, you can get the index of a stringlist as such: string[index]).

=) Strings and variables are interchangible now (which is why you can do: player.chat == "Woop!")
__________________
In a world of change... Who'll you believe?
Reply With Quote
  #11  
Old 05-16-2005, 11:54 PM
Evil_Trunks Evil_Trunks is offline
Evil
Evil_Trunks's Avatar
Join Date: Dec 2004
Posts: 391
Evil_Trunks is on a distinguished road
Quote:
Originally Posted by Velox Cruentus
=) Strings and variables are interchangible now (which is why you can do: player.chat == "Woop!")
there is still a big speed difference between using numeric arrays and string lists/string arrays
__________________

Reply With Quote
  #12  
Old 05-17-2005, 01:22 AM
Velox Cruentus Velox Cruentus is offline
Registered User
Velox Cruentus's Avatar
Join Date: Dec 2004
Location: Quebec, Canada
Posts: 465
Velox Cruentus is on a distinguished road
Send a message via ICQ to Velox Cruentus Send a message via AIM to Velox Cruentus
Of course -- Digits take a lot less space then letters. It's pretty much known. Take this for example:

(-- binary, 2 bytes in length --)
5 (5) = 0000 0101
A (65) = 0100 0001

Now... Which one do you think has the least data to support? Plus they have to mention that the latter binary is a string. More calculations to make... Funness.
__________________
In a world of change... Who'll you believe?
Reply With Quote
  #13  
Old 05-17-2005, 01:40 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by Velox Cruentus
Of course -- Digits take a lot less space then letters
Dude, a digit is a character just as much as a letter is.

Quote:
(-- binary, 2 bytes in length --)
5 (5) = 0000 0101
A (65) = 0100 0001
Those representations are not two bytes long.

Quote:
Now... Which one do you think has the least data to support?
What are you attempting to prove? Both of those representations use the same amount of bytes.
__________________
Reply With Quote
  #14  
Old 05-17-2005, 01:49 AM
Velox Cruentus Velox Cruentus is offline
Registered User
Velox Cruentus's Avatar
Join Date: Dec 2004
Location: Quebec, Canada
Posts: 465
Velox Cruentus is on a distinguished road
Send a message via ICQ to Velox Cruentus Send a message via AIM to Velox Cruentus
They are? I thought numbers are directly equivelent to what they mean, whereas letters are...

A byte isn't 4 bits?
__________________
In a world of change... Who'll you believe?
Reply With Quote
  #15  
Old 05-17-2005, 01:56 AM
Kaimetsu Kaimetsu is offline
Script Monkey
Kaimetsu's Avatar
Join Date: May 2001
Posts: 18,222
Kaimetsu will become famous soon enough
Quote:
Originally Posted by Velox Cruentus
They are? I thought numbers are directly equivelent to what they mean, whereas letters are...
You said 'digit', not 'number'.

Quote:
A byte isn't 4 bits?
No.
__________________
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 01:56 AM.


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