destory object with id help?

Blitz3D Forums/Blitz3D Programming/destory object with id help?

Caton(Posted 2015) [#1]
I need help!
there are two objects with a type I want it to destory a object as the id object

like id=0 will = object1
like id-1 will = object2

Code
------------------------
MonsterTempId$=Input$("Type the Monster Id: ")
For monster.monsters = Each monsters
If monster\monsterid=MonsterTempId$ Then
FreeEntity monster\monstermesh
FreeEntity monster\monsterentity
Delete monster
----------------------------------


Matty(Posted 2015) [#2]
Yeah....that looks fine....except you're probably freeing the same entity twice....Assuming youre getting an error...


What's the problem?


Zethrax(Posted 2015) [#3]
Not entirely sure what question your asking, but your code seems on the right track.

Note that if you've got either your main entity or mesh entity parented to the other then you only need to free the parent.

Graphics3D 800, 600, 0, 2

Type monsters
	Field monsterid$
	Field monstermesh
	Field monsterentity
End Type

monster.monsters = New monsters
monster\monstermesh = CreateCube()
monster\monsterentity = CreatePivot()
monster\monsterid$ = "Cookie Monster"

out_flag = False
Repeat
MonsterTempId$ = Input$( "Type the Monster Id: " )
For monster.monsters = Each monsters
	If monster\monsterid$ = MonsterTempId$
		FreeEntity monster\monstermesh
		FreeEntity monster\monsterentity
		Delete monster
		Print "You slew the monster!"
		out_flag = True
		Exit
	Else
		Print "Wrong monster. Try again."
		Print
	EndIf
Next
Until out_flag

WaitKey
End



Caton(Posted 2015) [#4]
Code
------------------------
;New Monster
Monster\MonsterId=Monster\MonsterId+1
;createmonstercube
----------------------------------
like destory every of that type of current id


Caton(Posted 2015) [#5]
and I used camerapick but how do I make it where it will do something when a 3d object is picked?


Matty(Posted 2015) [#6]
Have you looked at the samples?


Zethrax(Posted 2015) [#7]
For monster.monsters = Each monsters
If monster\monsterid = MonsterTempId
FreeEntity monster\entity_handle
Delete monster
EndIf
Next

Don't really know what more you need than that son. You loop through the list looking for IDs that match the one you want to delete, and then delete the object and it's associated media, objects, whatever.


RemiD(Posted 2015) [#8]
Another way to retrieve an entity in a list, without wasting time searching all the entries of a list, and it also shows you how to retrieve the id/handle of a collidable/pickable after a collision/linepick/camerapick :

with type list :
http://www.blitzbasic.com/codearcs/codearcs.php?code=3095

with dim arrays :
http://www.blitzbasic.com/codearcs/codearcs.php?code=3094


Zethrax(Posted 2015) [#9]
Here's an example of camerapicking.



Anything that you need to camera pick should have a type object associated with it that contains all the things you need to know about it.

eg.
Type T_enemy
Field entity_handle
Field health%
End Type

enemy.T_enemy = New T_enemy
enemy\entity_handle = CreatePivot()
EntityRadius enemy\entity_handle, 1.0
EntityPickMode enemy\entity_handle, 1
enemy\health = 100.0

NameEntity enemy\entity_handle, Handle( enemy ) ; Store the type object pointer.

; Your code to camera pick the enemy entity would go here.
; Let's assume that the camera pick code returned a valid entity handle and that
; > we've placed that handle into the variable 'entity_hit_handle'.

enemy_hit.T_enemy = Object.T_enemy( EntityName( entity_hit_handle ) ) ; Retrieve the type object pointer.

enemy_hit\health = enemy_hit\health - 10.0


Use the Handle and Object commands along with NameEntity and EntityName to store and retrieve a pointer to the type object in the entity's name-string. Links below.

http://www.blitzbasic.com/Community/posts.php?topic=53348
http://www.blitzbasic.com/b3ddocs/command.php?name=NameEntity&ref=3d_cat
http://www.blitzbasic.com/b3ddocs/command.php?name=EntityName&ref=3d_cat