Page 1 of 1

Function to set a local variable

Posted: Mon Dec 30, 2019 10:44 pm
by kaveh1000
Hi folks. I might be missing something very simple. When I use a function, normally I return a value that is then used locally. For example

Code: Select all

put square_it(6) into tSquare

function square_it pNumber
  return pNumber * pNumber
end square_it
tSquare now has value 36.

Now what I am looking for is to say:

Code: Select all

get square_it(6, tSquare)

function square_it pNumber, pVariable
...
end square_it
After calling it, the local value, tSquare, should automatically have the value 36. Assume it has not been declared as global, local, or script local.

Any ideas?

Re: Function to set a local variable

Posted: Mon Dec 30, 2019 10:50 pm
by FourthWorld
See the "@" operator in the Dictionary for handling arguments by reference, e.g.:

Code: Select all

function square_it pNumber, @pVariable 

Re: Function to set a local variable

Posted: Mon Dec 30, 2019 10:56 pm
by Klaus
Hi Kaveh,
Any ideas?
Yes, do not use a function but a handler and do not use variables, they HAVE to be declared somehow and somewhere!
Use a custom property instead like this:

Code: Select all

command square_it pNumber
   set the cNameThisPropertyAsYouLike of this stack to pNumber*pNumber
end square_it
But maybe I do not really understand what you are looking for... :D


Best

Klaus

Re: Function to set a local variable

Posted: Mon Dec 30, 2019 11:30 pm
by kaveh1000
Thank you both for the fast replies. Richard, you got it. I had no idea about this but it works! Thank you so much.

And Klaus thanks for reminder about custom properties which have saved the day many times!