Type Conversions+Object Command
Blitz3D Forums/Blitz3D Beginners Area/Type Conversions+Object Command
| ||
Hi, I am having a little trouble with types here. My code looks like this Function CreateParticle(mass#,x#,y#,z#) ; Function creates a particle particle.particle= New Particle ;sets up various aspects of the new particle particle\mass= mass ;set particle mass particle\oldx= x ;sets particles x, y and z particle\oldy= y particle\oldz= z particle\name= Handle(particle) ;stores the particles pointer in particle\name PositionEntity particle\name,oldx,oldy,oldz Return particle\name End Function Function CreateConstraint(p1%,p2%,stretch#,length#=3) constraint.constraint= New Constraint constraint\p1=Object.particle(p1) constraint\p2=Object.particle(p2) constraint\stretch=stretch constraint\length=length End Function The bit that is not working is constraint\p1=Object.particle(p1) constraint\p2=Object.particle(p2) so basically I want constraint\p1 to be a pointer to the actual particle.particle type. Also an explanation of the object command would probably help me. Lots of questions here. Any help is appreciated. |
| ||
How are the p1 and p2 fields defined in the type, they should have a .particle defintion after them:Type constraint ... Field p1.particle Field p2.particle ... End type Also in the CreateParticle function, you are not positioning the particle correctly, as you cannot use positionentity with a type, but only with pivots, meshes, sprites etc: ... ;PositionEntity particle\name,oldx,oldy,oldz ;the above doesn´t work, so use something like the next line, the oldx, oldy and oldz variables should be from the type I think: PositionEntity particle\entity,particle\oldx,particle\oldy,particle\oldz Return particle\name End Function Hope this explains it somehow. |
| ||
Hi, Thanks for responding. I have altered my CreateParticle() to do what you said. How are the p1 and p2 fields defined in the type, they should have a .particle defintion after them: A quick question about this. If I were to set up my fields like Field p1.particle would I be able to refer to them as constraint\p1 or would I have to refer to them as contraint\p1.particle or something like that. If the below one is true is their another way to accomplih this. |
| ||
You would refer to them as constraint\p1, as it is defined in the type declaration that it refers to a type called particle. You could also use the other. |
| ||
Okay thanks |
| ||
Oh one more question? Say my particle type was likeType Particle Field blah Field mass# Field blah and in the constraint type I had the bit about p1.particle. I am able to acess the fields of the particle through the constraint. Something like par1.particle=constraint\p1\mass if so how would I do that? |
| ||
par1.particle=constraint\p1\massThis has the form: par1.particle = something where the something *must* be a particle. No other kind of value can be assigned to par1.particle. In your example code the something is a number. This is an error. One possible legal assignment is par1.particle = constraint\p1 This is valid because constraint\p1 is a particle. |