[Math] Assign Unique Id

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Now, I have a 8x8 grid.
How do I assign an unique id to each of the squares? What formula to use?
*I need a formula that can return a unit number of each squares which is less than 8191.

8x8.jpg
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
(x - 1) + 8 * (y - 1)

This will go from 0 to 65 which is the best you can do.

So the location (3,7) would be
(3 - 1) + 8 * (7 - 1) = 50.

edit: If you increase your grid to let's say 30 colums and rows then your formula will be
(x - 1) + 30 * (y - 1)
and the maximum number you will then get is 30*30 - 1 = 899
 

Azlier

Old World Ghost
Reaction score
461
>The editor doesn't have them

vJass supports 2D arrays. And, last I checked, Gals uses vJass.

Yes, they're artifical, but still...
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
>>You could use 2D arraies.
Maybe I would learn it.

>>I would actually do it a little different:
How would that differs from ace's?
 

Azlier

Old World Ghost
Reaction score
461
2D arrays are simple.

JASS:
globals
    unit array LolArray [12][12]
    //Actually uses 144 array slots. 12*12.
endglobals
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> x*8+y

Well, given the requirements, using 10 instead of 8 has the advantage of the "index" being readable.
If you see 42 for example, you know it comes from 4 and 2,
whereas with x * 8 + y... you need to think about it first :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top