Dont really understand types passed to functions

BlitzMax Forums/BlitzMax Beginners Area/Dont really understand types passed to functions

dothedru22(Posted 2006) [#1]
I'm coming from C and in blitz max when passing a type to a function, does the function modify the actual elements of the type instead of making a copy?

I wouldnt normally do this in c but my main loops looks something like this

While Not(KeyDown(KEY_ESCAPE))
	
	UpdateCar(car)
	UpdateRoad(road)
	Flip()
	Cls()		
Wend
End	



Function UpdateCar(c:TCar)
	
	UpdateCollision(c)
	DrawImage(c.img , c.x , c.y)
	UpdateKeyboard(c)	
End Function

Function UpdateKeyboard(c:TCar)

	If KeyDown(KEY_RIGHT) 	c.x :+ c.speed
	If KeyDown(KEY_LEFT) 	c.x :- c.speed		
End Function



what im trying to ask is memory wise is this the right thing to do in blitz max. its a little wierd not using pointers and stuff.


tonyg(Posted 2006) [#2]
The function works against the actual instance of the type so 'memory wise' you're OK.
However, I'm not sure why you pass the car instance handle to a function called updatecar rather than make update a method of the TCar type and call it using car.update()


Dreamora(Posted 2006) [#3]
Yes it is the right thing.

Types in BM are always references (typesafe pointers if you want to call them like this) to objects and thus this stuff works.

There is no way to send an object "by value", only numerics are sent like this normally.


Chris C(Posted 2006) [#4]
Local s:String="hello "
addworld(s)
Print s

Function addworld(r:String Var)
r=r+"world!"
EndFunction

...