More newbie 'type' questions
Blitz3D Forums/Blitz3D Beginners Area/More newbie 'type' questions
| ||
How do I pass a type in a function? I need to pass the... errr......player number to my function. For example my type is pdata.......player number is p.pdata. How do I set it to player 2 (for example) and send that to the function? function(p) or function(p.pdata) doesn't work. |
| ||
How do I pass a type in a function? 1) Define your custom type (yours is pdata, you said, so...) Type pdata Field PlayerName$ End Type 2) Define your function to accept a parameter of pdata type, like this: Function MyFunction(p.pdata) ; "p" is the pdata-type variable that you pass in .... End Function 3) Create a new instance of your pdata type and assign it to a variable player1.pdata = New pdata 4) Pass it in to your function MyFunction(player1) This works because MyFunction is expecting a parameter of "pdata" type (see the ".pdata" in the parameter list, as opposed to "$", or "%", or "#", etc), and you're passing in a variable that you defined as "pdata"-type in step 3. |
| ||
Got it, thanks :) |