Functions?

Hi to all.
I’m a bit confused with the functions.
I’ve read every tutorial or help but I still don’t get if it’s possible to change a Parameter (number) in a function?

Example: add a number or another parameter to another parameter (if they are numbers, obviously) and give the result.
Or, create a function “sum” that sum two variables that I have transferred as Parameters.

You can’t pass a variable to a function, I mean that there is not a “Variable” parameter type but “Number” and “String”, so when you call a function you don’t pass a variable itself (the variable name only) but the variable value (Variable(myVar) or VariableString(myVar)) :slight_smile:

This means you can’t modify a variable passed to a function within the function itself, at least not in a generic way. If you have more info there could be workarounds, for example if the variable is a child you can pass the variable name as a string and read/modify it in the function (prentVar[“childNameString”]), but you’ve to know the parent variable name…

For the return value, functions don’t return anything (GD events system doesn’t know what the heck a “return” is :laughing: ), the closest approach is writing the returning value in a known variable. Imagine you’ve a function called “myFunc” that must return the sum of the given numbers, the idea would be to set a variable “myFuncReturn” value = parameter 1 + parameter 2. Then in the rest of the event you can use the “returned” variable. If you give to the return variable a predictable name you don’t have to remember or recheck what the returned variable is each time.