noob type help

Blitz3D Forums/Blitz3D Beginners Area/noob type help

im trying to change 1 of 4 picked types fields ,but im new to types and dont have a clue how to do this. can someone please show me how this is done. thanks.
(i know the code below wouldn't work i just wanted to show what i mean)

dim character (4)

type character
field life
end type

If CameraPick(cam,MouseX(),MouseY()) = character(4) Then
If MouseHit(1) Then

character\life = character\life - 2
EndIf
EndIf

why not loop through all of them, if its only 4 then it shouldn't be to bad of a performance hit.
type character
field life,ent
end type

;later in a function or in the loop
for char.character=each character

If MouseHit(1)    ; i rearranged these 2 lines for performance
If CameraPick(cam,MouseX(),MouseY()) = char/ent Then

char\life = char\life - 2
EndIf
EndIf 
next


thanks for the help mtnhome3d but that didnt seem to work :( .

oh well i didn't actually test it, i'll write an example now.


ok here's my example
Graphics3D 800,600,32
SetBuffer BackBuffer()

Type player
Field e;for entity
Field life
End Type

Global cam;makes it accessable in the function

;set up scene

cam=CreateCamera()
CreateLight();note this has no variable so we cant access this later but its still there

p.player=New player ;creates a list for the type
p\e=CreateCube(); creates a cube under the p\e var
p\life=100;sets p\e to 100
PositionEntity p\e,0,0,30;puts it 30 units infront of the camera
EntityPickMode p\e,2;sets it to be pickable
EntityColor p\e,234,65,107; sets a random color that i pulled out of a hat :)


While Not KeyHit(1)

pick_on_player();this is the function that uses the type

UpdateWorld
RenderWorld
Rect MouseX(),MouseY(),10,10,1
Flip
Wend
End


Function pick_on_player()


For p.player=Each player;access the type

If MouseHit(1)
If CameraPick(cam,MouseX(),MouseY()) = p\e Then

p\life = p\life - 2
CameraClsColor cam,235,65,78

EndIf
EndIf 

Next;loop to "p" or stop accessing the type

End Function


thank you for the example mtnhome3d its helped me understand types a lot better. I tried to add a second cube but it didnt work properly. Could you add a second cube to your example please?.

Use this tutorial;

http://www.hpquest.com/techlord/apps/AOBPwB3D/

thanks mortiis, I had trouble finding a good tutorial.

to add another cube you do this
for q=1 to 2; this sets the number of cubes you want 
p.player=New player ; creates a list for the type
p\e=CreateCube(); creates a cube under the p\e var
p\life=100;sets p\e to 100
PositionEntity p\e,rnd(-10,10),rnd(-10,10),30; puts it 30 units infront of the camera
EntityPickMode p\e,2;sets it to be pickable
EntityColor p\e,234,65,107; sets a random color that i pulled out of a hat :)
next


thanx again mtnhome3d, when i tried to add another cube before you posted your last example i used "for i = 1 to 2 " but only one cube was being affected by the campick (which is whats happening now) and i presumed i hadn't done it correctly, I also tried using the this.pointer from the tutorial but that didnt work either, do you know why only one cube is affected by the pick now?