Sorry if this has been covered elsewhere but I have searched the forum and couldn't find the answer.How do I pass a typed array to a function and manipulate it's values?
TYPE Tfoo
bar
ENDTYPE
FUNCTION phoo: f[] AS Tfoo
FOREACH pf IN f[]
DEBUG pf.bar+"\n"
NEXT
ENDFUNCTION
Arrays are always passed by reference. Types, too.
Say I had a function that determined empty spaces on a grid.This could obviously be used in several differant games.Would I always have the name of the type the same in each game or is there any way of passing the name of the type to the function. eg function phoo:f[] as whatever type name. or would the name of the type have to be hardcoded into the function.
No, you dont need a function !
TYPE Tfoo
bar
ENDTYPE
LOCAL f[] AS Tfoo
WHILE TRUE
FOREACH pf IN f[]
DEBUG pf.bar+"\n"
NEXT
SHOWSCREEN
WEND
END
But that wouldn't be a reusable function.I don't want to be reinventing the wheel for every game I make.I would be handy if i hade a function library with premade files so that these could be included if I needed them.
then pack the TYPE and the function within the same gbas file.