You have two ways of doing it
First method - function affecting a global variable
The first is to use a global x variable (I find it better practice to to call all global variables glbl_x , or glbl_y to remind myself, but for know, we will keep to simply x.
global x
X = 1
Print X `this prints 1
MakeX2() `this adds 1 to the global variable x
Print X `this prints 2
MakeX2() `this adds 1 to the global variable x
Print X `this prints 3
END
Function MakeX2()
REM This adds 1 to the global variable x
X = X + 1
EndFunction
The function doesn't need any inputs (nothing in the brackets, although they need to be there) and no output, so nothing comes after the EndFunction.
Second method
X = 1
Print X ` This prints 1
X=MakeX2(X) ` This sends the value of X to the function, and assigns the new value returned (2) back to X
Print X ` This prints 2
X=MakeX2(X) ` This sends the value of X to the function, and assigns the new value returned (3) back to X
Print X ` This prints 3
END
Function MakeX2(X)
REM This adds one to whatever value was sent to it (note value, not variable!) and returns the new value.
X = X + 1
EndFunction X
This function needs an input (in the brackets) which is an integer value and returns an output, after the EndFunction. When you call the function, you need to assign the answer of the function to something - in this case, as you want to increase X, you need to set X to the new value.
What may be confusing you in the second example is using X in the main program, and also in the function - they are in fact two different variables! One X can only be seen in the main loop, and the other can only be seen whilst you are in the function. To make it easy, we can rewrite example 2.
MainX = 1
Print MainX ` This prints 1
MainX=MakeX2(MainX) ` This sends the value of X to the function, and assigns the new value returned (2) back to X
Print MainX ` This prints 2
MainX=MakeX2(MainX) ` This sends the value of X to the function, and assigns the new value returned (3) back to X
Print MainX ` This prints 3
END
Function MakeX2(FuncX)
REM This adds one to whatever value was sent to it (note value, not variable!) and returns the new value.
FuncX = FuncX + 1
EndFunction FuncX
I hope this helps to clarify things.