passing a type variable to a function

Blitz3D Forums/Blitz3D Beginners Area/passing a type variable to a function

Dax Trajero(Posted 2004) [#1]
how would I do this:

player(1)\lives = 0

by passing the variable to a function ?

eg.

reset_life( player(1)\lives )
.
.
.
function reset_life ( param )

param = 0

end function


GitTech(Posted 2004) [#2]
Type TExample
	Field param
End Type

Function FunctionExample(t.TExample)
	t\param=0
End Function


EDIT: Just updated it :)


MSW(Posted 2004) [#3]
erm...like this?


player(1)\lives = reset_life()
.
.
.
function reset_life%()
Return 0
end function



or like this:

reset_lives(player(1))
.
.
.
Function reset_lives(player.playertype)

player\lives = 0

End function


Maybe I'm not understanding exactly what you are trying to do?

but per your example, this wouldn't work either:

A% = 1

Print A

increase_variable(A)

Print A


Function increase_variable(param)

param = param + 1

End function


Dax Trajero(Posted 2004) [#4]
here's what I'm trying to do.

Type playerdata
Field speed
Field strength
End Type

Dim player.playerdata(4)

player.playedate(1) = New playerdata
player.playedate(2) = New playerdata

player(1)\strength=1
player(2)\strength=7

increment_lives ( player(1)\strength )
increment_lives ( player(2)\strength )

;------------------------

Function increment_lives ( somethinghere )

somethinghere = somethinghere + 1
eg. player(1)\strength = player(1)\strength + 1

End Function

;-------------------------

I want the function to take whatever type variable I pass it and increment it.


GitTech(Posted 2004) [#5]
Type playerdata 
	Field speed 
	Field strength 
End Type 

Dim player.playerdata(4) 

player.playedate(1) = New playerdata 
player.playedate(2) = New playerdata 

player(1)\strength=1 
player(2)\strength=7 

increment_lives ( player(1)) 
increment_lives ( player(2)) 

;------------------------ 

Function increment_lives ( somethinghere.playerdata ) 

	somethinghere\strength = somethinghere\strength + 1 

End Function 

;-------------------------



Dax Trajero(Posted 2004) [#6]
cool - thanks for that

types are a little new to me!