Ok im having a dumb moment here, im currently working on a small puzzle game and in the game you select entities from a table and if the entity that is picked matches the previous picked entity's class then it would remove the two entities. I have it so I can detect which entity is picked and I can get the class from that entity but im unsure on how to tell it to hold that entity and wait for the second click and if second click matches remove the entities if it doesnt then clear the clicks and start over. I hope i explained this enough so someone can help me out.
objects of the same kind.
Blitz3D Forums/Blitz3D Programming/objects of the same kind. Okay your classes are held in a type right?
Well if they are then you could do something invloving
And the this part reflects the type you are checking, along with the click1.object part. They should match.
click1.object
this.object
Well if they are then you could do something invloving
Global click1.object Global curclick ;Rest of code in the For loop for checking each one If MouseHit(1) Select curclick Case 0 click1=this Case 1 If click1\class=this\class Then Hurray! End Select curclick=Not curclick EndIf
And the this part reflects the type you are checking, along with the click1.object part. They should match.
click1.object
this.object
The Pick commands return an entity, and the only custom information you can store in an entity is its Name. Store the "class" of the entity in EntityName. Either that, or set it to a Handle() to the object which is represented by that entity. If you have different types, prefix the EntityName with a string identifier so that you'll know which type of object you have a handle for.
EDIT: whoops, I need to learn to read:
Use a variable to keep track of the previously picked entity. When an entity is picked, if there's no previous, assign the new entity to the previous; if there is a previous, compare their classes. If the classes are the same, remove both entities. Reset the previously picked entity variable to 0 (Null if you're using objects). See the main loop of the code above for an example of all this.
Graphics3D 800,600 Global camera = CreateCamera() PositionEntity(camera, 0, 0, -40) Global light = CreateLight() TurnEntity(light, 50, 60, 0) Type token Field shape$ Field entity End Type For i = 1 To 100 t.token = New token Select Rand(1, 3) Case 1 t\shape = "CUBE" t\entity = CreateCube() EntityColor(t\entity, 0, 0, 255) Case 2 t\shape = "SPHERE" t\entity = CreateSphere() EntityColor(t\entity, 255, 0, 0) Case 3 t\shape = "CONE" t\entity = CreateCone() EntityColor(t\entity, 255, 255, 0) End Select PositionEntity(t\entity, Rnd(-15,15), Rnd(-15,15), Rnd(-15,15)) EntityPickMode(t\entity, 2) ; poly NameEntity(t\entity, "token" + Handle(t)) Next Local selected_token.token = Null While Not KeyHit(1) Local clicked_token.token = Null If MouseHit(1) Then picked_entity = CameraPick(camera, MouseX(), MouseY()) If picked_entity <> 0 Then picked_entity_name$ = EntityName(picked_entity) If Left$(picked_entity_name$, 5) = "token" Then foo$ = Mid$(picked_entity_name$, 6) clicked_token = Object.token(Mid$(picked_entity_name$, 6)) EndIf EndIf EndIf If selected_token <> Null And clicked_token <> Null Then If selected_token\shape = clicked_token\shape And selected_token <> clicked_token Then FreeEntity(selected_token\entity) FreeEntity(clicked_token\entity) Delete selected_token Delete clicked_token Else EntityAlpha(selected_token\entity, 1) EndIf selected_token = Null clicked_token = Null EndIf If selected_token = Null And clicked_token <> Null Then selected_token = clicked_token EndIf If selected_token <> Null Then cycle = cycle + 1 EntityAlpha(selected_token\entity, Sin(cycle*10)*.2 + .5) EndIf RenderWorld Flip Wend End
EDIT: whoops, I need to learn to read:
I have it so I can detect which entity is picked and I can get the class from that entity
Use a variable to keep track of the previously picked entity. When an entity is picked, if there's no previous, assign the new entity to the previous; if there is a previous, compare their classes. If the classes are the same, remove both entities. Reset the previously picked entity variable to 0 (Null if you're using objects). See the main loop of the code above for an example of all this.
thanks guys ill check this out when I get home.