In case you guys don't know, I like to find solutions to strange problems. In Warcraft 3 I was developing a library to that used psuedo-units that linked to unit-groups to provide theoretically unlimited selection sizes. It worked in theory, but there was no way to detect units in the selection box so I had to give up the project.
This time I want to tackle local dynamic arrays. Global dynamic arrays are essentially impossible, but I theorize I could create local dynamic arrays using functions to control array declarations and strings of variables linked together, but I'm not sure. What it would consist of is a bunch of single variables that get linked together in a chain then get passed into an array with the defined size (or if thats not possible, the arrays would be controlled by functions entirely). When the size gets changed, the old array would be scrapped and a new array would have the data fed into it (if the arrays are not controlled by functions).
What do you guys think about this? Is it possible? Useful? Already implemented? (I haven't checked)
If people think that this is actually an achievable goal, then I'll start working on it as soon as next week to complement the Generation System I am working on. However, I am notorious of starting projects and leaving them unfinished, but I'll see what I can do. I also have college classes starting monday, but I'd really like to tackle this problem. I believe vJASS for Warcraft 3 tackled this problem so I'm hoping I can tackle this problem.
I'll assume you're talking about actual code here and not galaxy editor macros since you posted this in the galaxy scripting section.
Global dynamic arrays wouldn't be any less feasible than local arrays, the issue is just implementation and performance.
We can only allocate arrays using a constant size, so doing it the old fashioned way allocating an array with capacity and position then growing that array as elements are added beyond it's capacity is not possible.
So that leaves using something like a CVS to hold the values, which is defiantly not optimal for performance.
So yes it is possible altough the backend will have to be implemented as a completely different type of data store, in which case you might want to expose the semantics of that data store instead.
If it is useful, well I can't say that I've come across a scenario where I actually needed it. When I do, I go back and check what would be local to implement as game objects (units, behaviours etc) which in most cases works out better than it would be when handled by triggers.
That's just my opinion tho, If someone can bring a scenario to the table where dynamic allocation is needed, please do :)
I'm not too sure about global dynamic arrays just because I haven't really flushed out the idea on how it would even work. Globals have to be declared at the beginning of code and cannot initially be set by a function as I know it.
local dynamic arrays just seem to be a more easier problem to tackle due to the simple nature of declaring globals.
I'll see what I can do, it's just a fun challenge for me.
There is no difference between how you declare a local variable vs a global, only the scope differs.
Even with a local array, you need a constant size, i.e a literal value or a constant defined as a literal value.
You can use the bank as a dynamic allocation, thats the only collection of variable size that i'm aware of. It is essentially a dictionary that is saved to a file, when you say to.
But you need to be careful when using banks for dynamic storage to not save them or you junk up the bank directory like crazy. If the map saves and loads data from previous plays, and you also want to use a bank as a form of "Session" dictionary, then set the banks to a global variable at map init.
That is the way any program works. It allocates a large pool, called the heap, and then allocates from there. This is true of C, Java, etc... The size of the pool can be set at compile-time by the user to meet the program's needs.
What exactly do you mean by dynamic arrays? Do you mean an array that you can resize such as array[0-10] and instead resize its dimensions to array[0-3] at run time?
From my understanding you cant really do this but why bother. Just set the array for the max size you ever intend to use and leave it be.
That may not be very good on memory, but whats it matter. SC2 aready runs at 2gig of ram on my box at home. Good thing I have 8gigs of ram huh.
Or you can also store arrays in strings. Since an array is basically a string(or a string is an array meh). There is support in the built in string operations for "Get Word From String" I have made use of this and it works very well.
I see up above people talking about Local VS Global arrrays. If you want the data available out side your current scope make a global.... other wise use a local.
If you really need a dynamic array at run time I suggest using String manipulation at run time you might be supprised by what you can do.
He doesn't search for a way to reduce the memory requirements of SC2 by a mb or two - but SC2 has a maximum allocation limit of about 2.5 MB. If the amount of variables in your map exceed that.. well you're fked.
What the hell are you doing to exeed 2.5 MB of data.... In variables?
So Say I have a whole bunch of data i need explosed globally
and i Make a StringArray[0-20][0-100] and you can basically make inner array within the string variable indexs in this array. Your telling me you cant do this and keep your data under 2md.
How could you possibly have that much data for a map...?
Does anybody know what max string size is ?
Does anybody know how many strings with max string size it takes to crash the game?
I also make use of splitting strings with the word functionality, but its probably one of the slower ways of accessing data. You're parsing a string everytime you're fetching a value, and in that its only a very slow 1d array.
Just use the bank for dynamic sizes. Its a data table / dictionary, they're fast and, I think, more powerful because you can access values by name.
You can also technically pass a collection of values by section name now that I think about it...
Considering the Trigger system is slow in any real time situation what does it matter if it takes a bit more power to parse a string then getting a variable from an array. IMO CPU's handle all the heavy lifting and its hardly noticable to the end user.
So far ive found that any attempt to run a trigger in Real time bassically Lags teh hell outta the game. ie, this is why everybody complains about wasd movement.
So considering your fetching data on a non-realtime basis. what does it matter if it takes .00001 seconds longer?
Can you possibly give us a screen shot of accessing and manipulationg the Bank From triggers? I mean with out the GE scripting stuff I mean just the actions available.