Is it possible to have an array as a parameter to an action?

Slapshot136

Divide et impera
Reaction score
471
I seem to have the array option for local variables, but not for parameters (using a unit variable) - is there any reason for this? or a workaround? or am I just doing it wrong?
 

jonas

You can change this now in User CP.
Reaction score
64
It should be possible to pass a reference to an array that lives in the global memory or deeper in the stack.
 

Slapshot136

Divide et impera
Reaction score
471
If the array was in global memory, there wouldn't be much need to pass it as a parameter - not sure I understand what you mean by "deeper in the stack", but lets say I have a function foo which currently takes two units as a parameter - I want to change it to take a unit[2] instead (to make it prettier) - is there any way to do so? (OK, it's a bit uglier in my case than a single unit[2], but you get the idea)
 

jonas

You can change this now in User CP.
Reaction score
64
The galaxy version should still work, that post is unrelated. By the way, you can always use the old 2d array tricks. You could look at the generated code of jasshelper for the dynamic arrays if you're not sure about the details, but it's really just using a global 2d array... I'm pretty sure that this can also be done in GUI.
 

Slapshot136

Divide et impera
Reaction score
471
using a global array seems.. inefficient.. but I guess it would work as a work-around (albeit more inefficient than a proper parameter)
 

jonas

You can change this now in User CP.
Reaction score
64
EDIT: The performance should be about on the same level. In one case you might have the compiler initializing the array when allocate it on the stack, in the other case you have some more loads abd arithmetic (loading the base address of the 2d array, adding the index from the variable). Depending on whether you want to keep references around or just pass them as you described, you might have to add some free list to manage the references which are being in use - slightly more code and performance overhead. Either way, don't worry about it too much and don't expect a slowdown greater than 2x. Struct usage in JASS was worse (+OP Limit and slow speed of JASS), and no one ever had problems with it.

It's just less beautiful and practical (in that it limits your recursion depth and requires you to have a huge portion of the memory in stand-by mode).
 
Last edited:
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top