arrays
- Qurqirish Dragon
- Genie
- Posts: 1011
- Joined: 06 Jan 2006
- Location: Flying the skies of Ohlam
Re: arrays
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.vhilhu wrote:so, i got that indexed variables = 1-dimensional array, but is there any way to make a 2d array?
i.e.:
Code: Select all
!!VRy1:S[1st index]*10+[2nd coordinate]+[base value];
!!VRvy1:[whatever value you want to store]
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:vhilhu wrote:how can adding up these 3 things work like a 2d array?
- 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
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.
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.
Who is online
Users browsing this forum: No registered users and 0 guests