arrays

Official forum of the Wake of Gods mod to Heroes of Might and Magic III.
vhilhu
Druid
Druid
Posts: 863
Joined: 13 Aug 2006

arrays

Unread postby vhilhu » 25 Nov 2006, 12:37

so, i got that indexed variables = 1-dimensional array, but is there any way to make a 2d array?

User avatar
Qurqirish Dragon
Genie
Genie
Posts: 1011
Joined: 06 Jan 2006
Location: Flying the skies of Ohlam

Re: arrays

Unread postby Qurqirish Dragon » 25 Nov 2006, 13:59

vhilhu wrote:so, i got that indexed variables = 1-dimensional array, but is there any way to make a 2d array?
Not in the traditional sense. The best you could do is probably to make an easy index chart. For example, if you wanted a 10x10 array, with indices 0..9 in each position then you could calculate an index first, and then use indirect referencing.

i.e.:

Code: Select all

!!VRy1:S[1st index]*10+[2nd coordinate]+[base value];
!!VRvy1:[whatever value you want to store]
anything in brackets is the value/variable indicated within. Base value is the first v-var for the array (i.e. array(0,0))

vhilhu
Druid
Druid
Posts: 863
Joined: 13 Aug 2006

Unread postby vhilhu » 25 Nov 2006, 14:51

uh.

now im confused.

how can adding up these 3 things work like a 2d array?

Psyringe
Leprechaun
Leprechaun
Posts: 19
Joined: 26 Oct 2006
Location: Berlin, Germany

Unread postby Psyringe » 25 Nov 2006, 19:00

vhilhu wrote:how can adding up these 3 things work like a 2d array?
Think about it this way - say, you have an 8x6 2-d array. This can easily be converted into a 1-d array with 48 elements:

- elements (1) to (8) of the 1-d array would be elements (1,1) to (8,1) of the 2-d array

- elements (9) to (16) of the 1-d array would be elements (1,2) to (8,2) of the 2-d array

- elements (17) to (24) of the 1-d array would be elements (1,3) to (8,3) of the 2-d array

... and so on.

You can vusualize a 1-d array as a long line of entries, and a 2-d array as a *grid* of several columns of such lines. To transform a 2-d array into 1 1-d array you simply take each of these columns of the 2-d array and concatenate them to one long line of entries. Since all columns have the same number of entries, it's easy to find out where any given entry would be in the grid.

Hope that helps :)

vhilhu
Druid
Druid
Posts: 863
Joined: 13 Aug 2006

Unread postby vhilhu » 25 Nov 2006, 19:10

thx, i now understand :oex:

User avatar
Arkas
Peasant
Peasant
Posts: 56
Joined: 03 Nov 2006

Unread postby Arkas » 26 Nov 2006, 05:13

Here's a working example:

I used a similar method in my random battle script. I wanted to pick a random creature of a specific level. Well, for the original 8 towns (not the conflux level 8's, or neutrals) this worked out.

I picked a random number between 0 and 7, and a modifier based on hero level between 0 and 13. This made up an [8,14] array.

So what I basically did, was use 0-13 to be the level of the creature, (un-upgraded level 1 through upgraded level 7). The random 0-7 is the number of times 14 was added to my result.

So at level 0, and random number 0, I was fighting pikemen, if the random number was 1, then it would have 14 added to it one time and I'd be fighting centaurs, random number 2 and I was fighting 0 + (14x2) which is gremlins.

So the creatures for the first 8 towns are in an array of [8,14] with both indicies starting at 0. My random number picked the town, and the modifier based on hero level picked the level of creature.


Return to “Wake of Gods”

Who is online

Users browsing this forum: No registered users and 10 guests