| 09-01-2008, 08:23 PM | #1 |
I am sorry for asking this again, but I am trying to make another set of 2D arrays ... my problem is that although I do understand things sometimes, I have really short memory (mainly if I don't use them much). I am trying to make a 2D array like Name[Number from 0 to 10][Integer Value from 0 to 25] = booleanValue I know this can be done, I just forgot and now I can't complete the code: JASS://globals for teh tutorial's Core globals public integer array gamePlayers[11] public integer constant maxGamePlayers = 11 public integer maxMissions = 26 public constant integer arraySize = 27 //maxMissions + 1 public string array textQuests[26] public string currentQuest endglobals type missionsDone extends boolean array[arraySize] globals //lost! missionsDone array endglobals I am so lost I probably has stuff I don't need. Can some one clear my mind please ? |
| 09-01-2008, 09:03 PM | #2 |
Try this Alternatively, you could just designate a block of arrays for a specific purpose (that's what I've done) i.e. JASS:function GetArrayIndex takes integer index1, integer index2 returns integer return ((index - 1) * BLOCK_SIZE) + index2 endfunction //BLOCK_SIZE being the number of array slots available to each 'block' //You may have to subtract 1 from index2, I forget how arrays work in JASS, especially with sized arrays :P So, the equivalent of [10][14] with block size 15 Code:
((10 - 1) * 15) + 14 9*15 + 14 135+14 149 is your array index |
| 09-01-2008, 09:03 PM | #3 |
2D array is... globals integer max_columns=20 // must be not 0 (zero) endglobals set column=10 set row=2 set myarray[column+row*max_columns]=x aka set myarray[10+2*20]=x btw 10+2*20 this must be less than 8191. (not equal) other wise this alg is "corrupted" well it's the fastest way to do 2d arrays. (for dynamic calculations) 2d arrays are good for data sets. anyway i didn't read what you wrote i just reply to the thread title xD |
| 09-01-2008, 09:20 PM | #4 |
there is another way of doing so, with vJASS, that I used on my spell GolemInvocation, however I forgot how it is built ... =S Can some one help me remember it ? |
| 09-01-2008, 09:28 PM | #5 |
Check the thread(s) you posted about your Golem Invocation spell, and check the spell's code itself? |
| 09-01-2008, 09:29 PM | #6 | |
Quote:
The textmacro makes it lame though. I think there is another way keeping the speed and the lack of complications. What you posted needs you to initialize each of the first indexes. |
| 09-01-2008, 09:48 PM | #7 | |
Quote:
I know when I have to use ".create" I am just lost with all the logic, can you tell me whixh variables I should use ? |
| 09-01-2008, 09:56 PM | #8 |
The Golem Invocation's implementation of 2D arrays isn't as neat as the one the-thingy linked you to, try using that one. |
| 09-01-2008, 10:17 PM | #9 |
edit: Read this |
| 09-01-2008, 10:55 PM | #10 |
Damn, only have the compiler from JNGP (I dunno how to use it without it xD). If the other way is better, why did you force me to use vJASS way ? I thought that way was better =S Anyway, I kinda need to get used of using it, because I will need that to make a system of parallel arrays. Can some one explain me better ? |
| 09-01-2008, 11:06 PM | #11 |
i wonder if vex can implement something like JASS:struct Cache ...do some gamecahce stuff with operator overload for mission key and key endstruct local Cache C = Cache.create("c.w3v") set C[2][5] = 22 //2 is mission key and 5 is key, and ofc we can do: set C["x"]["y"]=GetLocationZ(someLoc) |
| 09-02-2008, 09:10 AM | #12 |
Well, I am not using cache, but globals variables as you see. Can some one help me use 2D arrays ? Jesus, if I ever understand this thing again, I am so going to do a tutorial about this things ... no one seems to know how to use tehm at all ! |
| 09-02-2008, 02:22 PM | #13 |
how do 2d arrays work and what are they good for? |
| 09-02-2008, 04:09 PM | #14 | ||
Quote:
I just found out this a few minutes/hours ago: JASS:type iar extends integer array[3] //this is the small array. type iar_ar extends iar array[3] //this is the big array. Each slot of this array will have an array iar inside //here we create and fill ou 2D dynamic array function test takes nothing returns arsample local iar_ar r = iar_ar.create() //here we create the big array //we prepare our counters local integer i = 0 local integer j loop exitwhen (i == iar_ar.size) //holds size of the array type //in this line we create a small array for each slot of the big array set r[i]=iar.create() //this loop will fill the small array slots with values set j = 0 loop exitwhen (j == iar.size) set r[i][j] = j * i set j=j+1 endloop set i = i + 1 endloop return r endfunction Quote:
http://www.wc3campaigns.net/showthread.php?t=102102 and for system, like this will be the case. Ok, I've been studying vex's example, and then I merged it with Anitarf's example. This is pretty much equal to Ani's example, but with two major differences: 1 - I made it all from zero, and now I understand it's full mechanic, I believe I am closer to understand Anitarf's thinking. 2 - This doesn't compile Can some one please tell me why won't this compile ?? Error: isMissionDone is not of type that allows .syntax JASS:type isMissionDone extends boolean array[27] //small array globals //this is the BIG array with 11 slots. //Each one of this slots will then have small array with 27 slots public playerMissions array isMissionDone[11] endglobals //=========================================================================== private function SetMissionArray takes nothing returns nothing local integer i = 0 loop exitwhen (i == 11) //in this line we create a small array with 27 slots for each slot of "gamePlayers" set playerMissions[i] = isMissionDone.create() set i = i + 1 endloop endfunction |
| 09-02-2008, 04:12 PM | #15 |
JASS:public playerMissions array isMissionDone[11] |
