Types Again

Blitz3D Forums/Blitz3D Beginners Area/Types Again

pc_tek(Posted 2010) [#1]
Hi all!

I have the following code...



...but the compiler complains about 'sa' in the function. My original code is pages and pages long, it takes me ages to scroll up and down...which is why I split the code up into functions.

Is there a way to allow the use of 'sa\' to identify the current type?


Who was John Galt?(Posted 2010) [#2]
The sa inside your function is a local variable. It is not the same as declared outside.

You either need to make sa global so it is seen in the function, or pass it as a parameter to the function.


pc_tek(Posted 2010) [#3]
If I pass 'sa' with the function then I get an 'illegal type conversion'...




...If I make 'sa' global, I get a 'variable type mismatch'...



Matty(Posted 2010) [#4]
Type static_animation
	Field x,y
End Type

For sa.static_animation=Each static_animation
	UPDATE_Sprites(sa.static_animation)
Next

Function UPDATE_Sprites(sa.static_animation)
	sa\x=10
End Function


try that.


pc_tek(Posted 2010) [#5]
Cheers Matty!!!!

It seems logical now I see it.


Matty(Posted 2010) [#6]
One more thing...just in case you didn't realise this:

You can also do this:
Type static_animation
	Field x,y
End Type

For sa.static_animation=Each static_animation
	UPDATE_Sprites(sa.static_animation)
Next

Function UPDATE_Sprites(alternatevariablename.static_animation)
	alternatevariablename\x=10
End Function


ie, the function parameters specified don't have to have the same variable name as when called, as long as the data type (integer/float/string/custom type) is consistent.


Charrua(Posted 2010) [#7]
hi

you can use global typed variables, your try were ok, but if you start declaring : Global sa, then blitz asumes it is an integer variable and when it sees that varible intended to use as typed, it gives you the "mismatch"

;Global sa	;if you declare the varible this way, blitz supose that the variable is an integer one
;then, when you use it as a typed variable blitz found a type mismatch
Type static_animation
	Field x,y
End Type

;but you can declare it as typed:
Global sa.static_animation	;and then use it without redecalring its type

For sa = Each static_animation
	UPDATE_Sprites
Next

Function UPDATE_Sprites()
	sa\x=10
End Function



but, if posible, i prefere to use typed vars like matty

Juan


pc_tek(Posted 2010) [#8]
Thanks fellas.

20 years in programming and I'm just discovering the benefits of Types...go figure :)