Help me.

Blitz3D Forums/Blitz3D Programming/Help me.

Yue(Posted 2016) [#1]
For cubes.TCube = Each TCube
				
				
				If PickedEntity() <> 0 Then	
					
                                         ; Set value windows position Cubes, only one cube work. 
                                         ; more cubes no work. 
					alSetValueI( Windows\posX%, EntityX( cubes\cube% ))
					alSetValueI( Windows\posY%, EntityY( cubes\cube% ))
					alSetValueI( Windows\posZ%, EntityZ( cubes\cube% ))
					
				End If

Next



The problem is that while you have a single cube and touch it with the mouse pointer, I returned and I updated the inspector window in its current position.

But if I put more buckets, that fact does not return me to the window, any suggestions?

One Cube ok, return position Cube ( Cube Red )

Error, no return position cubes.



Bobysait(Posted 2016) [#2]
I guess you're trying to fill the inspector with the "picked" entity position ...

You need to check if PickedEntity() is the cube you picked, not just check if it is "<>0"
In your code, what you did is :
find if something has been picked, no matter what, and set the window textfields with the position
As long as you test each cubes, you just set the window again and again until the last cube.
Finally, the window only remains the last cube position (which is probably the grey one on your screen, which is probably at 0,0,0)

This is how you "can" do it :
; eventually, test before if something has been picked -> else you will just traverse the cubes for no reason.
If PickedEntity()<>0
	; now we now something has been picked
	; traverse the cubes and find the entity picked in the list.
	For cubes.TCube = Each TCube
				
				; if pickedentity is one of the cube ...
				If PickedEntity() = cubes\cube
					
                                         ; Set value windows position with the picked cube position
					alSetValueI( Windows\posX%, EntityX( cubes\cube% ))
					alSetValueI( Windows\posY%, EntityY( cubes\cube% ))
					alSetValueI( Windows\posZ%, EntityZ( cubes\cube% ))
					; small otpimization : quit the "For" Loop
					; as you have found the picked cube, you don't need to check others.
					Exit
				End If

	Next
EndIf




But there is an easier solution !
This is how you "should" do it :

-> name your cubes with the TCube "Handle" when you create them
(I don't know how your creation looks like, but that's just an example)

Local CubeMesh = CreateCube() ; the blitz3d entity
Local c.TCube = New TCube ; your type instance
c\cube = CubeMesh; link the entity to the type
NameEntity CubeMesh, Handle(c) ; link the type to the entity


Now, your cubes entities contains something like a pointer to the type that you use to store them.
-> so you can access the type directly by using the command "Object"

for example, your code above would now look like this
Local obj = PickedEntity() ; the last picked entity (if any)
If obj<>0 ; check if the entity exists or you just didn't pick anything
	; look at the obj's name, if it's a valid TCube handle, you can use it.
	Local c.TCube = Object.TCube(EntityName(obj))
	; if it's a TCube object, then c is not "Null"
	If c<>Null
		; so you directly found the TCube object without any need to traverse all objects.
		alSetValueI( Windows\posX%, EntityX( c\cube% ))
		alSetValueI( Windows\posY%, EntityY( c\cube% ))
		alSetValueI( Windows\posZ%, EntityZ( c\cube% ))
	EndIf
EndIf




Then, all of this is only good if you really want to assert the picked entity is a TCube instance before feeding your inspector ...
But, if all you need is to set the inspector with the current picked entity position, then, you just need PickedEntity() without extra useless stuff.
-> PickedEntity already holds the handle of the entity you picked ^^
Local obj = PickedEntity()
If obj<>0
	alSetValueI( Windows\posX%, EntityX( obj ))
	alSetValueI( Windows\posY%, EntityY( obj ))
	alSetValueI( Windows\posZ%, EntityZ( obj ))
EndIf

Simple enough.




So, you have at least 3 solutions, just choose the right one that better fit your needs ;)


Yue(Posted 2016) [#3]
Thanks You.

Here Init Type Cube
; - Tipo TCubo.
; -------------------
Type TCubo
	
	Field cubo
	Field padre%
	
End Type 

Global nCubo%
; - Init TCubo / Objeto.
; -------------------
Function Init_TCubo.TCubo( padre% = False )
	
	Local cubo.TCubo 	= New TCubo
	nCubo% = nCubo% + 1
	
	
	
	
	cubo\padre% 		= padre% 
	cubo\cubo%			= CreateCube( cubo\padre% ) 
	
	EntityPickMode		( cubo\cubo%, 2 ) 
	
	
	Return ( cubo.TCubo ) 
	
End Function 

; - Eliminar cubos.
; -------------------
Function DeInit_TCubos%()
	
	Local cubos.TCubo = Null 
	
	For cubos.TCubo = Each TCubo 
		
		
		If ( cubos\padre% ) Then 
			
			
			EntityParent ( cubos\padre%, False ) 
			
		End If 
		
		
		If ( cubos\padre% ) Then 
			
			FreeEntity ( cubos\cubo% ) 
			cubos\cubo%  =  0
			
		End If 
		
		
		
		
	Next 
	
	Delete Each TCubo
	
End Function 


Solution for You, perfect.

For cubos.TCubo = Each TCubo
			
			
			If PickedEntity()  = cubos\cubo% Then 


NameEntity on Init_TCube()??

NameEntity Name en windows properties??


Bobysait(Posted 2016) [#4]


Then in your picking loop you can go directly to the "TCubo" object



Yue(Posted 2016) [#5]
I think I have something new to learn. :(

http://www.blitzbasic.com/Community/posts.php?topic=53348


Yue(Posted 2016) [#6]
The inconveneinte I have, is that by picking the entity, and move on to the properties window collection value is lost, and can not set the properties of the entity.