Passing subtypes as Function parameters
Blitz3D Forums/Blitz3D Programming/Passing subtypes as Function parameters
| ||
To date I've been using an array of Joints() and an array of Objects(). I realized it'd be smarter to consolidate the two, so the Object class now has a joint field...TYPE joint Field pos.vector field joint_type END TYPE TYPE obj Field pos.vector Field size Field joint.joint END TYPE DIM objects.obj(10) FOR n=0 to 10 objects(n)=NEW obj objects(n)\pos.vector=NEW vector objects(n)\joint.joint=NEW joint objects(n)\joint\pos.vector=NEW vector NEXT Only now my function create_joint doesn't work. FUNCTION Create_Joint(j.joint)
IF j\joint_type
blah blah blah
END IF
END FUNCTIONThe object 'j' = Null ; it hasn't been created when called with Create_Joint(objects(n)\joint) How do I pass the joint sub-object as a function parameter? |
| ||
If you attempted to Create_Joint(objects(n)\joint) after the For...Next, n=11 therefor it is Null. You should try calling the function within the For...Next.
Type vector
Field x#
Field y#
Field z#
End Type
Type joint
Field pos.vector
Field joint_type
End Type
Type obj
Field pos.vector
Field size
Field joint.joint
End Type
Dim objects.obj(10)
For n=0 To 10
objects(n)=New obj
objects(n)\pos.vector=New vector
objects(n)\joint.joint=New joint
objects(n)\joint\joint_type=n ;<-- a lil test
objects(n)\joint\pos.vector=New vector
Create_Joint(objects(n)\joint)
Next
WaitKey()
Function Create_Joint(j.joint)
Print "jointtype="+j\joint_type
End Function
|
| ||
| Sorry, the n was just illustrative. The code and types above are only very brief examples. In the case of my actual program, I perform the For...next initialisation loop for 50 objects, and the create_joint() function shows it's fault when referencing objects(5). This is the first object I need to create a joint for. |
| ||
| My fault (always is, but it helps to find faults when posted publically!). I was passing the wrong object. |