entity doesn't exist
Blitz3D Forums/Blitz3D Beginners Area/entity doesn't exist
| ||
The code given below gives me an error entity doesn't exist, I am trying to pass a value of string variable to a function hin$="hinge" When it is called in function open_door(), it is giving the error entity doesn't exist, I can not sort out what mistake I have made as I am not an experienced programmer. Thanks in advance... Graphics3D 800,600 SetBuffer BackBuffer() type_camera=1 type_door=2 camera=CreateCamera() PositionEntity camera ,0,0,-5 EntityType camera,type_camera EntityRadius camera,2,2 pl=CreatePlane() PositionEntity pl,0,-5,0 grass_tex=LoadTexture( "E:\NEERAJ\IMG\PL.JPG" ) EntityTexture pl,grass_tex Global hinge=CreatePivot() PositionEntity hinge,9,0,0 Global door=CreateCube(hinge) ScaleEntity door,2,3,.2 PositionEntity door,2,-1,0 doortex=LoadTexture("E:\NEERAJ\wings3d\doorwood.jpg") EntityTexture door,doortex EntityType door,type_door EntityType door,type_door Collisions type_camera,type_door,2,2 HidePointer() Global door_open=0 Global door_status=0 hin$="hinge" While Not KeyDown( 1 ) If KeyHit(57) Then If door_status=0 Then door_open=1 ElseIf door_status=1 Then door_open=2 EndIf EndIf If door_open=1 Then open_door(hin$) ElseIf door_open=2 Then close_door() EndIf If KeyDown(200)=True Then MoveEntity camera,0,0,.03 If KeyDown(208)=True Then MoveEntity camera,0,0,-.03 If KeyDown(203)=True Then MoveEntity camera,-.2,0,0 If KeyDown(205)=True Then MoveEntity camera,.2,0,0 If KeyDown(30)=True Then MoveEntity camera,0,.2,0 If KeyDown(44)=True Then MoveEntity camera,0,-.2,0 xspd#=(MouseXSpeed()-xspd)/13 yspd#=(MouseYSpeed()-yspd)/13 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2 TurnEntity camera,0,-xspd#,0 UpdateWorld RenderWorld Flip Wend End Function open_door(hin$) RotateEntity hin$,EntityPitch(hin$),EntityYaw(hin$)+.2,EntityRoll(hin$) If EntityYaw(hin$)>93 Then door_status=1 door_open=0 End If End Function Function close_door(hin$) RotateEntity hin$, EntityPitch(hin$),EntityYaw(hin$)-.2,EntityRoll(hin$) If EntityYaw(hin$)=<0 Then door_status=0 door_open=0 End If End Function |
| ||
Okay....I think you've misunderstood how this works a little. Your value of hin$ simply contains the alpha numeric string "hinge". That is not an entity handle. Instead you need to pass the handle to the entity which is stored in one of the variables either hinge or door. The actual type of variable for hinge or door is simply an integer but blitz uses the number stored in it as a reference to the actual entity. Hope that helps a little. - Try passing hinge or door to the function instead. |
| ||
@Matty The reason behind not passing the variable directly to the function is that, suppose I have a house model which have 3 doors in it and I want the door to open which the player collides with and press the space key, so the hin$ will contain different door handle based on the collision with the door. If player collides with the door1 then hin$=door1 If player collides with the door2 then hin$=door2 If player collides with the door3 then hin$=door3 |
| ||
You have to do what Matty has suggested, it is simple: To make this code work, replace every hin$ with hin and replace hin$="hinge" with hin=hinge The reason is, for RotateEntity to work, it needs the number (handle) of the object,which the variable hinge contains. |
| ||
Yes Dan, you are right. Now it is working fine. Thanks a lot. |