SC2Mapster Forums

Development > Galaxy Scripting

Q: How to pass array as refference into function?

  • 3 posts
    #1 Jan 03, 2013 at 08:23 UTC - 0 likes

    I need to pass an array as a parameter into a function, now before you start telling "but you cant...."

    Does Galaxy+ + editor make use of the * reference operator so that if I executed the function by script, I could theoretically pass the pointer leading back to the array into the function.

    Also, I need to calculate the length of an array. I know the number of indexes / keys does not change - is there a pre-existing .length() sizeof() , etc... C + + function that I can use without hacking the editor.

    Last edited Jan 03, 2013 by LitePollution9
    #2 Jan 03, 2013 at 17:15 UTC - 0 likes

    I'd suggest 2 things:

    1. If you plan to use multiple arrays, create an array of arrays, and pass the index of the array within this meta-array.

    2. Save array length in an additional variable after each add/remove element operation. It may be convenient to use structures, to store array and length variable within one variable. Or, if your array's type is int, you can use array[0] to store its length.

    Or, if you're 100% sure what value empty element has, you can create your length() function, which would search for index of the last not empty element.

    Last edited Jan 03, 2013 by Zolden
    #3 Jan 04, 2013 at 22:42 UTC - 0 likes

    http://www.sc2mapster.com/forums/development/galaxy-scripting-and-trigger-lib/38374-passing-arrays-as-parameters/

  • 3 posts

You must login to post a comment. Don't have an account? Register to get one!