string used for calling entity
Blitz3D Forums/Blitz3D Programming/string used for calling entity
| ||
Help me please, I have question (perhaps it's just straight forward): I have an entity called playerOne (which is a b3d-file). If I want to change the color of the entity, I just write: entitycolor playerOne,x,x,x NO problem, but: If I have two string-variables (a$, and b$) containing: a$="player", and b$="One", then what do I have to do, to be able to use them for pointing at my entity? example: entitycolor (a$+b$),x,x,x - I know this doesnt work, so do you have another suggestion? Best regards, Jesper Colding - Jørgensen |
| ||
playerone is not a string, it's a number! It's an integer Variable. Try this: Print PlayerOne and it will print a high number, a Handle that is used internally to access the model PlayerOne is something completely diffrent than "PlayerOne"! I assume you want to be able to access a number of diffrent players? You could do this with an Array of Variables: Dim player(10) player(1)=loadmesh("p1.b3b") player(2)=loadmesh("p2.b3b") player(3)=loadmesh("whatever.b3b") ... Now acces them however you want: entitycolor player(2),x,x,x |
| ||
i'd use types type player field model ,name$ end type basemodel = loadmesh("p1.b3d") for i = 1 to NoPlayers; = how many players you need p.player = new player p\model = copyentity(basemodel) p\names = "player"+str(i) next for p.player = each player if p\name$ = "player1" entitycolor p\model,x,x,x next |
| ||
blitz has a built in function for this.; Blitz3d template AppTitle "3D madness","GOODBYE!" ; check to see if a graphics mode exist then ; if so set it, if not display error If GfxMode3DExists (800,600,16) Graphics3D 800,600,16 Else RuntimeError "ACHTUNG! UPGRADE YOUR VIDEO CARD!" EndIf ; Create a camera . we see all 3d ; through this camera. you can have multiple ; cameras ; cam=CreateCamera() ; create a world camera MoveEntity cam,0,0,-15 ; move the camera "back" 5 units lite=CreateLight(2) ; create a light for our world MoveEntity lite,-20,20,-10 blob=CreateCube() ; create a cube and call it blob EntityPickMode blob,2 ; polygon pickable EntityColor blob,0,0,255 ; color our blob, red, green , blue NameEntity blob,"Harold" blob2=CreateCube() ; create a cube and call it blob2 EntityPickMode blob2,2 ; polygon pickable EntityColor blob2,0,255,0 ; color our blob, red, green , blue MoveEntity blob2,-3,3,0 NameEntity blob2,"George" blob3=CreateCube() ; create a cube and call it blob3 EntityPickMode blob3,2 ; polygon pickable EntityColor blob3,255,255,0 ; color our blob, red, green , blue MoveEntity blob3,3,3,0 NameEntity blob3,"Sylvester" Repeat ; * * * * beginning of loop mx# = MouseX() my# = MouseY() CameraPick cam,Mx#,my# Pickedname$ = "" ; reset pickedname$ to empty string If PickedEntity()<>0 ; if we picked something Pickedname$ = EntityName(PickedEntity()) If Pickedname$ = "Harold" TurnEntity blob,1,1,1 ; turnentity entity,x,y,z EndIf If Pickedname$ = "George" TurnEntity blob2,1,1,1 ; turnentity entity,x,y,z EndIf If Pickedname$ = "Sylvester" TurnEntity blob3,1,1,1 ; turnentity entity,x,y,z EndIf EndIf UpdateWorld RenderWorld ; render the 3d scene Text Mx#,my#+5,Pickedname$ Rect mx#-3,my#-3,6,6,0 Flip ; flip the buffer Until KeyDown(1)=1 ; * * * * end of loop ; check to see if key 1 (escape key) is pressed RuntimeError "adios amigos" End |
| ||
or try this one:; Blitz3d template SeedRnd(MilliSecs()) AppTitle "3D madness","GOODBYE!" ; check to see if a graphics mode exist then ; if so set it, if not display error If GfxMode3DExists (800,600,16) Graphics3D 800,600,16 Else RuntimeError "ACHTUNG! UPGRADE YOUR VIDEO CARD!" EndIf fntArialB=LoadFont("Arial",24,True) SetFont fntArialB ; Create a camera . we see all 3d ; through this camera. you can have multiple ; cameras ; cam=CreateCamera() ; create a world camera MoveEntity cam,8,8,-15 ; move the camera "back" 5 units lite=CreateLight() ; create a light for our world MoveEntity lite,-20,20,-10 Type cube Field Entity Field name$ Field rotate# Field red,green,blue End Type Restore names For x =1 To 4 For y = 1 To 4 foo.cube = New cube foo\entity = CreateCube() PositionEntity foo\entity,x*3,y*3,0 EntityPickMode foo\entity,2 EntityColor foo\entity,Rnd(0,155),Rnd(0,155),Rnd(0,155) Read this_name$ NameEntity foo\entity,this_name$ foo\name$ = this_name$ Next Next Repeat ; * * * * beginning of loop mx# = MouseX() my# = MouseY() CameraPick cam,Mx#,my# Pickedname$ = "" ; reset pickedname$ to empty string If PickedEntity()<>0 ; if we picked something Pickedname$ = EntityName(PickedEntity()) For foo.cube = Each cube ; cycle thru all foos If foo\name$ = Pickedname$ foo\rotate# =foo\rotate#+.03 EndIf Next EndIf For foo.cube = Each cube ; cycle thru all foos foo\rotate# =foo\rotate#*.99 TurnEntity foo\entity,foo\rotate#,foo\rotate#,foo\rotate# Next UpdateWorld RenderWorld ; render the 3d scene Color 255,255,0 Text Mx#,my#+5,Pickedname$ Color 255,0,0 Rect mx#-3,my#-3,6,6,0 Flip ; flip the buffer Until KeyDown(1)=1 ; * * * * end of loop ; check to see if key 1 (escape key) is pressed RuntimeError "adios amigos" End .names Data "sally","pud","doofus","Billy","Madison","spot","Claire","John" Data "spam","Samuel G Adamson III","Gigli","Greta","Bert","Ernie","Falco","Spud" |
| ||
a=createsphere() b=a moveentity b,100,100,100 it'll move entity a. a and b just show blitz where to look. when you create an entity, it just puts a number in your name variable. that number is the house address where blitz looks ;) |
| ||
I know what you're trying to do njesper. Strings, however, cannot be used in place of other variable handles because they are variables themselves. Your best bet, as already mentioned is to keep track of them yourself either by using arrays (i.e. Dim Player(MAX_PLAYERS) ) or using types, as demonstrated above. By all means use the code provided, but I suggest reading through it before you do so you understand how it works. That way you'll become a better programmer - its how I learnt myself! |
| ||
I will try to explain my code: 1. create a blitz entity 2. blitz has the built in functions NAMEENTITY and ENTITYNAME. NAMEENTITY assigns a String to the to the entity. 3. ENTITYNAME(foo) will return the name you assigned to the entity foo with the NAMEENTITY command. a$="player", and b$="One", then what do I have to do, to be able to use them for pointing at my entity? example: entitycolor (a$+b$),x,x,x - I know this doesnt work, so do you have another suggestion? is this what you need? ; Blitz3d template AppTitle "3D madness","GOODBYE!" ; check to see if a graphics mode exist then ; if so set it, if not display error If GfxMode3DExists (800,600,16) Graphics3D 800,600,16,2 : Else : RuntimeError "Achtung!":EndIf Cam = CreateCamera() ; create a world camera light = CreateLight() MoveEntity cam,0,0,-5 ; move the camera "back" 5 units blob=CreateCube() EntityColor blob,0,0,255 ; color our blob, red, green , blue NameEntity blob,"playerOne" a$="player" b$="One" Repeat ; * * * * beginning of loop ; here is where we test it If EntityName(blob) = a$+b$ TurnEntity blob,1,1,1 ; turnentity entity,x,y,z EntityColor blob,Rnd(0,55),Rnd(0,55),Rnd(0,55) EndIf RenderWorld ; render the 3d scene Text 0,0,"Entityname(blob)="+EntityName(blob)+" a$ = "+a$+" b$ = "+b$+ " a$+b$ = "+a$+b$ Flip ; flip the buffer Until KeyDown(1)=1 ; * * * * end of loop RuntimeError "Goodbye!" End |
| ||
WOW! you guys are amazing. I have been working in the movie-industry for ten years, with proffessional 3D-software, and you still dont get half as good a suppor, compared to this! ;-) THANKS. I solved the issue. Started using arrays together with types. Best regards, Jesper Colding - Jørgensen |