When you call the function with moveplayer(x#), you are passing the variable x# to be used by the function. At the end of your function, you are returning x# back to the caller, yet your caller is not written properly to accept return values.
If you had put x#=moveplayer(x#), then you wouldn't have a problem.
So change that line to read x#=moveplayer(x#).
Alternately, you could declare x as a global variable, and do away with passing the variables to/from the function.
Just remember, to pass data into a function, call it like DOTHIS(X). If you need data to be returned from the function, use A=DOTHIS(X) and also put a return value at the end of your ENDFUNCTION. And for functions to have their variable scope seen outside of the function (without passing the data directly), you must use global variables.