Jump to content

return a static variable as a "byref?"

Recommended Posts


func _somefunction ($text = "")
    local static $array[1][4] = [[1,2,3,4]]

    if $text <> "" then
      _ArrayAdd($array, "0|0|0|0")
      ;and other stuffs

    return $array


local $x = _somefunction()
$x[2][1] = 3;

The last line above, I want to store 3 into $x[2][1]. And I want this to be stored into the static $array.

Obviously, $x[2][1] = 3 is not working. How do I return $array of _somefunction as a "byref" such that I can modify it from outside?

I could simply declare $array as a global outside of the function, but I sure want to keep it isolated.

PS. I do not know if "return as a byref" is the proper term/phrase for this....


Link to post
Share on other sites

AFAIK, there is no way to directly change the values in a static variable with function scope from the global (not contained within a function) section of a script (without calling the function of course).

Now you could directly change the values of a static variable defined in function A in function B, if A (eventually) calls B and the static variable in A is passed as an argument to B as ByRef.


Code hard, but don’t hard code...

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...