Function to return multiple values?
BlitzMax Forums/BlitzMax Beginners Area/Function to return multiple values?
| ||
How do you return multiple values ex. X,Y,Z from a function? Do you return them as an array? Thanks! |
| ||
an array if they are of the same type, or a type that contains different field-value X,Y,Z |
| ||
Function DoStuff(X:Int Var,Y:Int Var,Z:Int Var) X=1 Y=2 Z=3 End Function Adding Var after the variable type passes the variable by reference instead of by value, which means that you're effectively passing a pointer and any changes you make to that variable within that function will be reflected in the original variable. |
| ||
Type AType Field x,y,z endtype Function aFunction:AType() return Temp:Atype EndFuctionMy feeling is that if the (3) things are so related that you are going to be returning them from a Function. Then make them a Type. And in the case of say Vertex points passing arrays is ok as well. Its down to what you preffer doing often But there is no single "correct" way to answer your question, there is nothing wrong with the "By refference" way |
| ||
Fantastic. Thanks all! |