Function Help
Blitz3D Forums/Blitz3D Beginners Area/Function Help
| ||
Hi everyone, Since I am new to Blitz and programming in general, I have only created basic user functions. I have a function with variable X for example how can I share this varible with another function and return the value to the original function without making the variable global? Thanks in advance. OneHitWonder |
| ||
You may need to correct it a bit. It has been a long time since I've used Blitz:Function afunction() x=7 y=function2(x) End Function Function function2(x);<--------- return x+1;x comes from ^ End Function |
| ||
Similar to AJ00200 - Function MyFunction() x = 123 ;some statements... ; ; ; x=AnotherFunction(x) End Function Function AnotherFunction(myParameter) myParameter = ;...some equation return myParameter End Function Note that if you want to return a string then the function needs to be declared as follows: Function MyFunction$() 'the $ after the function name indicates this function will return a string End Function If you want to return a floating point number then the function needs to be declared as follows: Function MyFloatFunction#() ;the # after the function name indicates a floating point number will be returned end function If you want to return a type instance then do as follows: Type MyType ;field a$,b$ ;etc ;field x,y,z, etc End Type Function MyFunction.MyType(parameter) ;eg MyTypeInstance.MyType=new MyType ;MyTypeInstance\x = 123 ;etc return MyTypeInstance.MyType ;return null - if you don't want to return an instance End Function ;if you want to pass a type then do the following: Type MyType ;field a$,b$ ;etc ;field x,y,z, etc End Type Function MyFunction(parameter.MyType) ;parameter\x = 123 ; End Function Note also that unlike standard variables (string, integer, float) which are passed by value, type instances are passed by reference. |
| ||
this answers it no need for me. |