method and function

BlitzMax Forums/BlitzMax Beginners Area/method and function

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I think I am right in saying that as far as types are concerned,

a method has implicit access to the data in the type but a function does not.

This means that if you call a function related to a type you must still pass an explicit reference to the the type instance concerned.

an example of a method and a non working function...
Type mytype

Field x,y,z

Method do_method()
x=1
y=2
z=3
End Method

 
Function do_function()
x=4
y=5
z=6
End Function

End Type


a:mytype =New mytype

a.do_method()
Print a.x+" "+a.y+" "+a.z

a.do_function()
Print a.x+" "+a.y+" "+a.z

WaitKey()
End

You see how the call to do_function() failed to change the data in the type.

An example of how to get the function working...
Type mytype

Field x,y,z

Method do_method()
x=1
y=2
z=3
End Method

 
Function do_function(thistype:mytype)
thistype.x=4
thistype.y=5
thistype.z=6
End Function

End Type


a:mytype =New mytype

a.do_method()
Print a.x+" "+a.y+" "+a.z

a.do_function(a)
Print a.x+" "+a.y+" "+a.z

WaitKey()
End

That, to the best of my knowledge is the difference.