FreeEntity not working

Blitz3D Forums/Blitz3D Beginners Area/FreeEntity not working

Could someone please explain to me why I can't seem to delete the mesh under the label .c1 in this code? I made it just to use as CopyMesh template, but now that I'm done, I can't seem to get rid of it! This is also happening less noticably throughout this example. If you look close, you can see some of the - supposed to be - alpha .25 meshes are actually at double what they should be, which is funny because why would something I made a copy of ever be affected by an alpha change made to it's copy?! I mean you delete the original, and then not only is it still there, but it's being affected by commands too? Help!! :)

Graphics3D 640,480,32,1
SetBuffer BackBuffer()

Global camera=CreateCamera()
PositionEntity camera,5,10,-20
RotateEntity camera,27.5,12.5,0
CameraZoom camera,1.6

Global horizontalbar0=CreateCube()
ScaleMesh horizontalbar0,50,.05,.05

Global horizontalbar1=CopyMesh(horizontalbar0)
Global horizontalbar2=CopyMesh(horizontalbar0)
Global horizontalbar3=CopyMesh(horizontalbar0)
Global horizontalbar4=CopyMesh(horizontalbar0)
Global horizontalbar5=CopyMesh(horizontalbar0)
Global horizontalbar6=CopyMesh(horizontalbar0)
Global horizontalbar7=CopyMesh(horizontalbar0)
Global horizontalbar8=CopyMesh(horizontalbar0)
Global horizontalbar9=CopyMesh(horizontalbar0)
Global horizontalbar10=CopyMesh(horizontalbar0)
Global horizontalbar11=CopyMesh(horizontalbar0)

PositionMesh horizontalbar1,0,0,-50
PositionMesh horizontalbar2,0,0,-40
PositionMesh horizontalbar3,0,0,-30
PositionMesh horizontalbar4,0,0,-20
PositionMesh horizontalbar5,0,0,-10
PositionMesh horizontalbar6,0,0,0
PositionMesh horizontalbar7,0,0,10
PositionMesh horizontalbar8,0,0,20
PositionMesh horizontalbar9,0,0,30
PositionMesh horizontalbar10,0,0,40
PositionMesh horizontalbar11,0,0,50

AddMesh(horizontalbar1,horizontalbar0)
AddMesh(horizontalbar2,horizontalbar0)
AddMesh(horizontalbar3,horizontalbar0)
AddMesh(horizontalbar4,horizontalbar0)
AddMesh(horizontalbar5,horizontalbar0)
AddMesh(horizontalbar6,horizontalbar0)
AddMesh(horizontalbar7,horizontalbar0)
AddMesh(horizontalbar8,horizontalbar0)
AddMesh(horizontalbar9,horizontalbar0)
AddMesh(horizontalbar10,horizontalbar0)
horizontalbar0footgrid=CopyMesh(horizontalbar0)
AddMesh(horizontalbar11,horizontalbar0)

Global horizontalbars=CopyMesh(horizontalbar0)

FreeEntity horizontalbar0
FreeEntity horizontalbar1
FreeEntity horizontalbar2
FreeEntity horizontalbar3
FreeEntity horizontalbar4
FreeEntity horizontalbar5
FreeEntity horizontalbar6
FreeEntity horizontalbar7
FreeEntity horizontalbar8
FreeEntity horizontalbar9
FreeEntity horizontalbar10
FreeEntity horizontalbar11

Global verticalbars=CopyMesh(horizontalbars)
RotateMesh verticalbars,0,90,0
AddMesh(verticalbars,horizontalbars)
Global tenfootgrid=CopyMesh(horizontalbars)

FreeEntity horizontalbars
FreeEntity verticalbars

PositionEntity tenfootgrid,0,-.15,0
EntityAlpha tenfootgrid,.25

Global horizontalbar1footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar2footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar3footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar4footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar5footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar6footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar7footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar8footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar9footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar10footgrid=CopyMesh(horizontalbar0footgrid)
Global horizontalbar11footgrid=CopyMesh(horizontalbar0footgrid)

PositionMesh horizontalbar1footgrid,0,0,1
PositionMesh horizontalbar2footgrid,0,0,2
PositionMesh horizontalbar3footgrid,0,0,3
PositionMesh horizontalbar4footgrid,0,0,4
PositionMesh horizontalbar5footgrid,0,0,5
PositionMesh horizontalbar6footgrid,0,0,6
PositionMesh horizontalbar7footgrid,0,0,7
PositionMesh horizontalbar8footgrid,0,0,8
PositionMesh horizontalbar9footgrid,0,0,9

AddMesh(horizontalbar2footgrid,horizontalbar1footgrid)
AddMesh(horizontalbar3footgrid,horizontalbar1footgrid)
AddMesh(horizontalbar4footgrid,horizontalbar1footgrid)
AddMesh(horizontalbar5footgrid,horizontalbar1footgrid)
AddMesh(horizontalbar6footgrid,horizontalbar1footgrid)
AddMesh(horizontalbar7footgrid,horizontalbar1footgrid)
AddMesh(horizontalbar8footgrid,horizontalbar1footgrid)
AddMesh(horizontalbar9footgrid,horizontalbar1footgrid)

.c1
FreeEntity horizontalbar0footgrid

FreeEntity horizontalbar2footgrid
FreeEntity horizontalbar3footgrid
FreeEntity horizontalbar4footgrid
FreeEntity horizontalbar5footgrid
FreeEntity horizontalbar6footgrid
FreeEntity horizontalbar7footgrid
FreeEntity horizontalbar8footgrid
FreeEntity horizontalbar9footgrid

EntityAlpha horizontalbar1footgrid,.25

While Not KeyHit(1)
UpdateWorld
RenderWorld
Flip
Wend
End


That's just one big headache and asking for trouble :o) I have no idea tbh. Don't you have a modeller you could do this in. You need to look into arrays also.

The only thing i can spot, is that the initial "horizontalbar0", is occupying the same space is "horizontalbar6" and therefore will overlap. That might be your problem.

Funny thing is, with my cube creation code I posted up in another thread, I tried something different with it yesterday. I tried making a main cube mesh that I can just copy the rest from. But then when I tried to remove surfaces from a copy, it effected them all, which makes no sense why.

I just went back to creating them when I needed them instead of copying from a single source.

Yeah - your code is bloated and confusing.

Is this what you want? Notice how much less code it takes ..

Graphics3D 640,480,32,1
SetBuffer BackBuffer()

Global camera=CreateCamera()
PositionEntity camera, 5,10,-20
RotateEntity camera,30,15,0
CameraZoom camera,1.6

Global bar=CreateCube()
ScaleMesh bar,50,.05,.05

Global Grid1 = CreateMesh()
Global Grid2 = CreateMesh() 
PositionEntity Grid2, 0,-.15, 0
EntityAlpha Grid2, .25

For l = - 50 To 50

	For d = 0 To 1
	
		copy = CopyMesh( bar )
		RotateMesh copy, 0 , d * 90 , 0
		PositionMesh copy, l * ( d=1 ) , 0 , l * ( d=0 )
		If ( l Mod 10 ) <> 0
			AddMesh copy, Grid2
		Else
			AddMesh copy, Grid1
		EndIf
		FreeEntity copy
		
	Next

Next		

FreeEntity Bar

While Not KeyHit(1)

	UpdateWorld
	RenderWorld
	Flip
	Wend

End



Funny thing is, with my cube creation code I posted up in another thread, I tried something different with it yesterday. I tried making a main cube mesh that I can just copy the rest from. But then when I tried to remove surfaces from a copy, it effected them all, which makes no sense why.



I assume you used copyentity rather than copymesh. In which case this is expected behaviour.

!!!! Yea I used copyentity, I didn't think there was a copymesh. I'll have to try that thanks. CopyEntity is also probably why my player characters go invisible when more than one player of the same model type is hit by the enemy (I use EntityAlpha).

Entityalpha works fine with instances ( copyentity ), it's only mesh manipulation commands what will effect all instances.

Well I just tried it for my Players and it doesn't copy animations so, I'll just have to try it for my ground pieces later.

Edit: Nope, I just tried using CopyMesh. It copied it, but there were two things I noticed were wrong.

The copy...

1. It wasn't flatshaded like it usually is
2. It only had 1 surface instead of 5 (5 for the left,right,top,bottom,front)

So... that's no good... I'll just have to use the old way, which works.

These aren't wrong - you're only copying mesh data with copymesh, not entity brush properties or animations so, again, this is expected behaviour.

If you are subsequently using addmesh then note that it combines surfaces which share the same brush properties - I'm guessing this is why the copy only has 1 surfaces instead of 5.

Wow that's alot of replies. I'm at the library right now and can't read and respond to all this, but I will tomorrow.

Firstly though, about it being bloated and confusing. I can't explain why, but for some reason ever since I first saw arrays I've hated them. I understand them, but I don't want to use them at all. I like having everything out on the table, not merged into one thing. It just makes coding more enjoyable for me. Sorry if it makes my posts annoying or something.

Secondly, this is all I really did in the code basically:
Make bar 0
Make three copies of it and move them into different positions
Combine bars 1, 2, and 3
Delete bar 0

Why bar 0 won't go away, and why it's being affected by further changes to the three merged bars such as changes to their transparency, are the main things I'm confused about. Sorry if any of this was already addressed in the later posts, but I'm almost out of time here! :)

You don't need to use arrays here, just a couple of simple loops as I've pointed out. If you find typing the same thing over and over more enjoyable than using loops or array's then so be it. Personally, I think it's just plain silly.

I'm sure you'll realise this once you start writing bigger programs and find them a debugging and maintainance nightmare.

Try writing minesweeper without types or arrays ;o)

(or banks)

Well, then we disagree. What else is new in the world, right?

So any ideas about what might be making it impossible to delete bar 0? Or why it's being affected by changes to other meshes? It's not because I used CopyEntity, I didn't, I used CopyMesh. I would like to solve this.

;PositionMesh horizontalbar6,0,0,0
;AddMesh(horizontalbar6,horizontalbar0)


As Ross has already pointed out bar 6 is in the same place as bar 0. Comment the lines above out and you'll see that it works.

Thanks, I'll give it a try.

Thanks guys!

http://files.filefront.com/Measurement+gridzip/;13029525;/fileinfo.html

Graphics3D 640,480,32,1
SetBuffer BackBuffer()
Const fps=30
period=1000/fps
time=MilliSecs()-period
elapsed%=0
ticks%=0
tween#=0
rt%=0

Global camera=CreateCamera()
PositionEntity camera,5,1,-20
CameraZoom camera,1.6
Global cameraturn#=0
AmbientLight 255,255,255

;music=PlayMusic ("secretofmanathelegend.mid")

Global gridoftens=CreateCube()
ScaleMesh gridoftens,50,.05,.05
PositionMesh gridoftens,0,0,-50

Global horizontalbar10=CopyMesh(gridoftens)
Global horizontalbar20=CopyMesh(gridoftens)
Global horizontalbar30=CopyMesh(gridoftens)
Global horizontalbar40=CopyMesh(gridoftens)
Global horizontalbar50=CopyMesh(gridoftens)
Global horizontalbar60=CopyMesh(gridoftens)
Global horizontalbar70=CopyMesh(gridoftens)
Global horizontalbar80=CopyMesh(gridoftens)
Global horizontalbar90=CopyMesh(gridoftens)
Global horizontalbar100=CopyMesh(gridoftens)

PositionMesh horizontalbar10,0,0,10
PositionMesh horizontalbar20,0,0,20
PositionMesh horizontalbar30,0,0,30
PositionMesh horizontalbar40,0,0,40
PositionMesh horizontalbar50,0,0,50
PositionMesh horizontalbar60,0,0,60
PositionMesh horizontalbar70,0,0,70
PositionMesh horizontalbar80,0,0,80
PositionMesh horizontalbar90,0,0,90
PositionMesh horizontalbar100,0,0,100

AddMesh(horizontalbar10,gridoftens)
AddMesh(horizontalbar20,gridoftens)
AddMesh(horizontalbar30,gridoftens)
AddMesh(horizontalbar40,gridoftens)
AddMesh(horizontalbar50,gridoftens)
AddMesh(horizontalbar60,gridoftens)
AddMesh(horizontalbar70,gridoftens)
AddMesh(horizontalbar80,gridoftens)
AddMesh(horizontalbar90,gridoftens)
Global gridofones=CopyMesh(gridoftens)
AddMesh(horizontalbar100,gridoftens)

FreeEntity horizontalbar10
FreeEntity horizontalbar20
FreeEntity horizontalbar30
FreeEntity horizontalbar40
FreeEntity horizontalbar50
FreeEntity horizontalbar60
FreeEntity horizontalbar70
FreeEntity horizontalbar80
FreeEntity horizontalbar90
FreeEntity horizontalbar100

Global verticalbar0=CopyMesh(gridoftens)
RotateMesh verticalbar0,0,90,0
AddMesh(verticalbar0,gridoftens)
FreeEntity verticalbar0

PositionEntity gridofones,0,-.05,1

Global horizontalbar2=CopyMesh(gridofones)
Global horizontalbar3=CopyMesh(gridofones)
Global horizontalbar4=CopyMesh(gridofones)
Global horizontalbar5=CopyMesh(gridofones)
Global horizontalbar6=CopyMesh(gridofones)
Global horizontalbar7=CopyMesh(gridofones)
Global horizontalbar8=CopyMesh(gridofones)
Global horizontalbar9=CopyMesh(gridofones)

PositionMesh horizontalbar2,0,0,1
PositionMesh horizontalbar3,0,0,2
PositionMesh horizontalbar4,0,0,3
PositionMesh horizontalbar5,0,0,4
PositionMesh horizontalbar6,0,0,5
PositionMesh horizontalbar7,0,0,6
PositionMesh horizontalbar8,0,0,7
PositionMesh horizontalbar9,0,0,8

AddMesh(horizontalbar2,gridofones)
AddMesh(horizontalbar3,gridofones)
AddMesh(horizontalbar4,gridofones)
AddMesh(horizontalbar5,gridofones)
AddMesh(horizontalbar6,gridofones)
AddMesh(horizontalbar7,gridofones)
AddMesh(horizontalbar8,gridofones)
AddMesh(horizontalbar9,gridofones)

FreeEntity horizontalbar2
FreeEntity horizontalbar3
FreeEntity horizontalbar4
FreeEntity horizontalbar5
FreeEntity horizontalbar6
FreeEntity horizontalbar7
FreeEntity horizontalbar8
FreeEntity horizontalbar9

Global verticalbar1=CopyMesh(gridofones)
RotateMesh verticalbar1,0,90,0
PositionMesh verticalbar1,-1,0,-1
AddMesh(verticalbar1,gridofones)
FreeEntity verticalbar1

Global gridplane=CreateCube()
ScaleMesh gridplane,50,.01,50
PositionMesh gridplane,0,-.05,0

EntityColor gridoftens,63,63,63
EntityColor gridofones,31,31,31
EntityColor gridplane,7,7,7

EntityAlpha gridofones,.9

While Not KeyHit(1)
Cls
Repeat
elapsed=MilliSecs()-time
Until elapsed
ticks=elapsed/period
tween#=Float(elapsed Mod period)/Float(period)
For rt=1 To ticks
time=time+period
If rt=ticks Then CaptureWorld

cameraspeed#=0
cameraclimb#=0

If KeyDown(208) cameraspeed=-.1
If KeyDown(200) cameraspeed=+.1
If KeyDown(157) cameraclimb=-.025
If KeyDown(54) cameraclimb=+.025

If KeyDown(205)
cameraturn=cameraturn-.5
ElseIf KeyDown(203)
cameraturn=cameraturn+.5
Else cameraturn=0
EndIf

If cameraturn>.5 cameraturn=.5
If cameraturn<-.5 cameraturn=-.5

TurnEntity camera,0,cameraturn,0
MoveEntity camera,0,cameraclimb,cameraspeed

UpdateWorld
Next
RenderWorld tween

Color 127,127,127
Text 0,0,"Controls: arrow keys, right shift, and right control. Esc to quit."

Flip
Wend
End