Main Menu

Passing types to functions

Started by ShadowCentaur, July 10, 2008, 08:56:07 PM

Previous topic - Next topic

ShadowCentaur

I'm writing a little two dimensional gas simulator and having some trouble passing types to functions.  I want to make a function that will spit out the dot product of two vectors (and later maybe the orthogonal projection). I keep getting a "Expecting coma's between 'dotproduct' Function declarations input parameters. What is it that I'm screwing up?

// a two dimensional vector
type tvector
   // x value
   x#
   // y value
   y#
endtype


// mainloopstuff in here
// compute the dot product of two vectors, a and b
function dotproduct(a as tvector, b as tvector)
   
   product#=a.x#*b.x#+a.y#*b.y#
   
   
   
endfunction product#

If you ever need me, click your heels three times and press Ctrl + Alt + Del.

kevin

#1
  This is all covered in the Help.  There's various tutorials in the help/About section for TYPES tutorial.


   This function accepts array passes for parameters A and B... which is ok if you want to pass typed variables / arrays & lists in as a whole, but you can't operate upon a particular element from within that container.  You get the whole structure (conatiners and all the elements)


function dotproduct(a.tvector, b.tvector)

endfunction



or, this version accept individual elements.  So the locals A and B are basically pointing at elements from a Variable/Array or List container.  They can't see the container this time though. 



     type  tvector
          x#,y#
     endtype

     Dim Vectors(100) as  tvector

    ; allocate a couple of them from the array
    Vectors(10)  = new tvector
    Vectors(20)  = new tvector

    ; call the dot product

    result#= dotproduct(Vectors(10), Vectors(20)


function dotproduct(a as tvector, b as tvector)

endfunction result#