![]() |
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: I believe there is another way of creating them for GS2 that is like old GS1 Quote:
If anyone could explain this to me and provide a couple of examples I would be extremely greatful. Thanks |
var = new[length];
var[x] = new[x]; Or: var = {{x,y},{x,y}}; You can grab the variables by: var[1][1]; |
Quote:
|
What's advantages does a multidimensional array have? I cannot understand any use.
|
it's basically an easier to use string list, i think
normally when you want to create a structure like this NPC Code:item1 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: you can access the items with: array[i][n] |
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[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:
PHP Code:
|
Ah, I see :)
|
This is a very nice addition. Saves me the trouble of creating so many separate arrays/string lists. Thanks all. :cool:
|
Quote:
|
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!") |
Quote:
|
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. |
Quote:
Quote:
Quote:
|
They are? I thought numbers are directly equivelent to what they mean, whereas letters are...
A byte isn't 4 bits? |
Quote:
Quote:
|
Ah. Yea... They are 8 bits. I thought it was 4 bit before. :-/
I meant 'number'. |
Quote:
Of course that is just my speculation, and only Stefan can really say (*nudge*) |
Quote:
Speed comparisons: String lists on serverside are really slow right now, although you need to use quite huge string lists to see a speed difference in the script. The string lists are more optimized on clientside. Also numeric arrays are much faster. In new scripting engine it is using the same mechanism for normal numeric arrays and for string lists. They are probably slightly slower than numeric arrays (10-20%), but of course much faster than string lists. With Graal version 4 you also have the advantage that the script engine is coded in C/C++, so even numeric arrays should be faster than with v2. |
Bad code detected:
Initializing multi-dimensional arrays is done like this arr = new[2][2][2] You can also intiialize the subarrays manually e.g. to get different sized subarrays, but stuff like new[2,2] will not work |
Quote:
|
| All times are GMT +2. The time now is 07:35 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.