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

Discussion in 'Starcraft 2 (SC2) Editor Help' started by Slapshot136, Mar 18, 2015.

  1. Slapshot136

    Slapshot136 Divide et impera

    Ratings:
    +483 / 2 / -0
    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?
     
  2. jonas

    jonas Well-Known Member

    Ratings:
    +42 / 4 / -0
    It should be possible to pass a reference to an array that lives in the global memory or deeper in the stack.
     
  3. Slapshot136

    Slapshot136 Divide et impera

    Ratings:
    +483 / 2 / -0
    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)
     
  4. jonas

    jonas Well-Known Member

    Ratings:
    +42 / 4 / -0
    • Useful Useful x 1
  5. Slapshot136

    Slapshot136 Divide et impera

    Ratings:
    +483 / 2 / -0
  6. jonas

    jonas Well-Known Member

    Ratings:
    +42 / 4 / -0
    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.
     
  7. Slapshot136

    Slapshot136 Divide et impera

    Ratings:
    +483 / 2 / -0
    using a global array seems.. inefficient.. but I guess it would work as a work-around (albeit more inefficient than a proper parameter)
     
  8. jonas

    jonas Well-Known Member

    Ratings:
    +42 / 4 / -0
    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: Mar 31, 2015

Share This Page