How types should work in a function

Blitz3D Forums/Blitz3D Beginners Area/How types should work in a function

bashc(Posted 2009) [#1]
I know there must be a way to do a type shows values into a function. But I donk know how should I do this in this expample in which I want to print all a array contain in a function as I have made out of function in main program for valoues was not "zero".

Sorry, but types are new for me and a "little" difficult still.

Graphics 640,480,16,2 

Type matriz
  Field x[5] 
  Field y[5]
  Field name$ [5]
End Type
Global x,y, name$

w.matriz = New matriz

      w\x[1] = 10
      w\y[1] = 8
      w\name$[1] = "poken"

      w\x[2] = 6
      w\y[2] = 1
      w\name$[2] = "branki"

      w\x[3] = 5
      w\y[3] = 11
      w\name$[3] = "kriyun"

      w\x[4] = 2
      w\y[4] = 9
      w\name$[4] = "Klussy"

      w\x[5] = 12
      w\y[5] = 19
      w\name$[5] = "Blidnken"

 
For j=1 To 5
Print Str$(j) + "  x="+ Str$(w\x[j])+ "  y=" +Str$(w\y[j])+ "  "+ w\name$[j]
Next


show.matriz()


WaitKey

End


Function show.matriz()
; this does not work dammnn!!...
 pf.matriz = New matriz
For j=1 To 5
Print Str$(j) + "  x="+ Str$(pf\x[j])+ "  y=" +Str$(pf\y[j])+ "  "+ pf\name$[j]
Next
End Function






Charrua(Posted 2009) [#2]
hi

pass the matriz to the function as a parameter:

Graphics 640,480,16,2 

Type matriz
  Field x[5] 
  Field y[5]
  Field name$ [5]
End Type
Global x,y, name$

w.matriz = New matriz

      w\x[1] = 10
      w\y[1] = 8
      w\name$[1] = "poken"

      w\x[2] = 6
      w\y[2] = 1
      w\name$[2] = "branki"

      w\x[3] = 5
      w\y[3] = 11
      w\name$[3] = "kriyun"

      w\x[4] = 2
      w\y[4] = 9
      w\name$[4] = "Klussy"

      w\x[5] = 12
      w\y[5] = 19
      w\name$[5] = "Blidnken"

 
For j=1 To 5
Print Str$(j) + "  x="+ Str$(w\x[j])+ "  y=" +Str$(w\y[j])+ "  "+ w\name$[j]
Next


show(w)	;send W as a parameter


WaitKey

End


Function show(pf.matriz)	;acept a type matiz variable
	For j=1 To 5
		Print Str$(j) + "  x="+ Str$(pf\x[j])+ "  y=" +Str$(pf\y[j])+ "  "+ pf\name$[j]
	Next
End Function



do only 2 changes, the 2 lines commented!

cheers

Juan


bashc(Posted 2009) [#3]
Great idea! it works, thank you very much Charrua and "Saludos desde Espaņa :)" = grettings from Spain ;)