Entity does not exist

Blitz3D Forums/Blitz3D Programming/Entity does not exist

JBazarra(Posted 2007) [#1]
This code run ok:

; Define the cubes Type
Type cubes
Field main
Field x, y
End Type

For tmp=1 To 10
onecube.cubes=New cubes
Next

Graphics3D 1024,768,2

Cam=CreateCamera()
Lit = CreateLight()

PositionEntity Lit,-5,-5,0
PositionEntity Cam,0,0,-8

temp=CreateCube()
HideEntity temp

WaitKey() ; When we hit key, 10 new cubes are created

For onecube.cubes=Each cubes
onecube\main=CopyEntity(temp)
EntityColor onecube\main,Rand(255),Rand(255),Rand(255)
PositionEntity onecube\main,Rand(-6,6),Rand(-6,6),Rand(8)

SeedRnd MilliSecs()
Delay 11
Next

RenderWorld
Text 0,0,counter
Flip

WaitKey()

End

But this not, and i need this structuring type. How can i solve it?

; Define the cubes Type
Type cubes
Field main
Field x, y
End Type

For tmp=1 To 10
onecube.cubes=New cubes
Next

Graphics3D 1024,768,2

Cam=CreateCamera()
Lit = CreateLight()

PositionEntity Lit,-5,-5,0
PositionEntity Cam,0,0,-8

temp=CreateCube()
HideEntity temp

WaitKey() ; When we hit key, 10 new cubes are created
Copy_cubes(onecube.cubes)

RenderWorld
Text 0,0,counter
Flip

WaitKey()

End


Function Copy_cubes(onecube.cubes)
For onecube.cubes=Each cubes
onecube\main=CopyEntity(temp)
EntityColor onecube\main,Rand(255),Rand(255),Rand(255)
PositionEntity onecube\main,Rand(-6,6),Rand(-6,6),Rand(8)

SeedRnd MilliSecs()
Delay 11
Next
End Function

Thank you :-)


Gabriel(Posted 2007) [#2]
There's no such thing as a 2 bit color depth to my knowledge, so that should either be

Graphics3d 1024,768,32


Or perhaps you meant

Graphics3d 1024,768,0,2


Your function cannot see a variable called temp because there isn't a variable within that function with that name and there are no global variables with that name. If you want your variable Temp in the main program to be accessible to functions, it needs to be global.

Global temp = CreateCube()


And now it's fine.


JBazarra(Posted 2007) [#3]
Oh, i read the command help and now i understand everything:

...This is a new entity instance of an existing entity's mesh! Anything you do to the original Mesh (such as RotateMesh) will effect all the copies...

I thought that the copy was a new entity and that she didn't require the original entity, for that reason i didn't put 'temp' global. jeje, i had never used CopyEntity in my programs.

Yes, i meant Graphics3D 1024,768,0,2
It is good the errors prevention in Blitz 3D because Graphics3D 1024,768,2 run ok in my pc ^^

Thank you.


Gabriel(Posted 2007) [#4]

I thought that the copy was a new entity and that she didn't require the original entity, for that reason i didn't put 'temp' global. jeje, i had never used CopyEntity in my programs.

Just for clarity, you still needed it to be global, whether CopyEntity used the same mesh or not. You're asking it to copy an entity, but it cannot see what entity you want it to copy because temp has no value within that function. A function only has access to variables within that function and global variables.


Dreamora(Posted 2007) [#5]
If you want to use mesh commands on the clone, use CopyMesh instead of CopyEntity. CopyEntity is to have different "transformations" on the same base mesh


boomboom(Posted 2007) [#6]
Wow...you read the command help and now understand 'everything'?


JBazarra(Posted 2007) [#7]
Yes boomboom, i understand the oficial explanation with respect to that command. Do you read and later you don't understand? hummm, then you have a problem ^^

Greetings and thanks to all for the explanations.

All the codes run ok:

; Define the cubes Type
Type cubes
Field main
End Type

For tmp=1 To 10: onecube.cubes=New cubes: Next
Graphics3D 1024,768,0,2
Camera=CreateCamera(): Light=CreateLight()
PositionEntity Light,-5,-5,0 : PositionEntity Camera,0,0,-8
temp=CreateCube(): HideEntity temp
WaitKey() ; When we hit key, 10 new cubes are created
For onecube.cubes=Each cubes
onecube\main=CopyEntity(temp) ;CopyMesh(temp)
EntityColor onecube\main,Rand(255),Rand(255),Rand(255)
PositionEntity onecube\main,Rand(-6,6),Rand(-6,6),Rand(8)
SeedRnd MilliSecs():Delay 11
Next
RenderWorld: Flip: WaitKey():End

----------

; Define the cubes Type
Type cubes
Field main
End Type
Global temp

For tmp=1 To 10: onecube.cubes=New cubes: Next
Graphics3D 1024,768,0,2
Camera=CreateCamera(): Light=CreateLight()
PositionEntity Light,-5,-5,0 : PositionEntity Camera,0,0,-8
temp=CreateCube(): HideEntity temp
WaitKey() ; When we hit key, 10 new cubes are created
Copy_cubes(onecube.cubes)
RenderWorld: Flip: WaitKey():End

Function Copy_cubes(onecube.cubes)
For onecube.cubes=Each cubes
onecube\main=CopyEntity(temp) ;CopyMesh(temp)
EntityColor onecube\main,Rand(255),Rand(255),Rand(255)
PositionEntity onecube\main,Rand(-6,6),Rand(-6,6),Rand(8)
SeedRnd MilliSecs()
Delay 11
Next
End Function

----------

; Define the cubes Type
Type cubes
Field main
End Type

For tmp=1 To 10: onecube.cubes=New cubes: Next
Graphics3D 1024,768,0,2
Camera=CreateCamera(): Light=CreateLight()
PositionEntity Light,-5,-5,0 : PositionEntity Camera,0,0,-8
WaitKey() ; When we hit key, 10 new cubes are created
Copy_cubes(onecube.cubes)
RenderWorld: Flip: WaitKey():End

Function Copy_cubes(onecube.cubes)
temp=CreateCube(): HideEntity temp
For onecube.cubes=Each cubes
onecube\main=CopyEntity(temp) ;CopyMesh(temp)
EntityColor onecube\main,Rand(255),Rand(255),Rand(255)
PositionEntity onecube\main,Rand(-6,6),Rand(-6,6),Rand(8)
SeedRnd MilliSecs(): Delay 11: Next
End Function

----------

; Define the cubes Type
Type cubes
Field main
End Type

For tmp=1 To 10: onecube.cubes=New cubes: Next
Graphics3D 1024,768,0,2
Camera=CreateCamera(): Light=CreateLight()
PositionEntity Light,-5,-5,0 : PositionEntity Camera,0,0,-8
temp=CreateCube(): HideEntity temp
WaitKey() ; When we hit key, 10 new cubes are created
Copy_cubes(onecube.cubes,temp)
RenderWorld: Flip: WaitKey():End

Function Copy_cubes(onecube.cubes,temp)
For onecube.cubes=Each cubes
onecube\main=CopyEntity(temp) ;CopyMesh(temp)
EntityColor onecube\main,Rand(255),Rand(255),Rand(255)
PositionEntity onecube\main,Rand(-6,6),Rand(-6,6),Rand(8)
SeedRnd MilliSecs()
Delay 11
Next
End Function