| 10-04-2007, 12:50 PM | #1 |
Yay! I've got a series of dummy abilities which link in to a series of units. When i cast one of these abilities i create a certain unit type and start a whole bunch of fun effects. My problem is that i can link the abilities and unit types into arrays, so i have an array of abilities and an array of unit types, i want to cast AbilityArray[1] and it'll spawn UnitType[1]. My problem is exactly how to do this? I'd rather have a nice compact trigger that runs through like this than have seperate ones for every ability\unit combo. |
| 10-04-2007, 12:54 PM | #2 |
Store that integer? It's the common denominator (I think that's the word). |
| 10-04-2007, 03:25 PM | #3 |
just use twin-linked lists, it force one more var reading and fixed order access, but allow you with out anyproblem map logical arrays of any size, extend then or flush onfly. |
| 10-04-2007, 07:31 PM | #4 | ||
Quote:
Quote:
In other words, just set the list up so that each pair of unit-ability is under the same index. Then when the number of one is called just apply that number to the other array's index to get it's matching unit/ability. |
| 10-04-2007, 07:40 PM | #5 |
Parallel arrays, you mean? Not linked lists. |
| 10-04-2007, 08:10 PM | #6 |
How many abilities do you have? If it's not too many you can linear search through the all of them (using parallel arrays ofcourse, you're already doing that). If you have many, you'll want to try some kind of pseudo-hashing stuff to reduce the large ability ids to numbers suitable to array indices. |
| 10-04-2007, 09:03 PM | #7 |
If you have more than 4, it is worth a hash. Get the ability id and then take the modulus of it to base 8000, and then go up from there (note that, unless you have several thousand, there is no need to ever loop; with 8191, you might need to loop, which would be slower for all due to the extra checks). |
| 10-05-2007, 01:40 PM | #8 |
Captain Griffen Lists can have different structure. you may keep data in "parralel array" or "array by link" first allow you get data faster second extend arrays onfly |
| 10-05-2007, 02:00 PM | #9 |
You can't extend arrays on the fly in JASS, and with vJASS arrays are very cheap so anything except parallel arrays for this is stupid. And I was replying to Salbrismind, who most definately WAS talking about parallel arrays. |
| 10-05-2007, 05:21 PM | #10 |
I can extend logical arrays onfly in JASS. Parralel Array: ... Slot 6 refers to slot 6 of data (Single array for single value)(cant add\remove arrays) List array: ... Slot 6 refers to slot 6*data offset of allocation list(allocation list is another array that stores logical array settings - size, last\first slots, and any other params inside it) After reading array's data we can start reading it or insert any data Second needs 2 more array readings but allow you to extend data onfly (change array size) This usefull if you need to manipulate growable data like custom orbs. |
| 10-06-2007, 01:12 AM | #11 |
I don't need to extend the data on the fly, so atm i'm using parallel arrays, but when an ability is cast, how do i find out which number it is on the array? |
| 10-06-2007, 01:33 AM | #12 |
Let's begin calling everything graphs! lists are graphs! trees are graphs! And graphs are graphs! |
| 10-06-2007, 02:53 AM | #13 | |
Quote:
I'm not the ultimate jass/trigger maker but all that i can think of is to make a bunch of if's like "if ability super bomb is cast set index to 1" It might all depend on how many you have and if they can be organized into different groups then they can be found faster. |
| 10-06-2007, 06:17 AM | #14 |
There has to be a better way than that. Atm i'm using a For loop to loop through and find the right one, but i'll end up with well over 100 abilities, so that's really not going to work. |
| 10-06-2007, 04:26 PM | #15 |
Do a simple 'hash' by finding the modulus of it (base 8000) and then working up until you find it. |
