quick question
Blitz3D Forums/Blitz3D Programming/quick question
| ||
if I have seven doors named door1,door2 door3 etc and I want to use a common command for all doors to identify them as a group, how can I code this. I dont want to use types for other reasons. I was thinking of something like this for d=1 to 7 if pick1=(door+"d") then do something endif next basically I want door to add the number "d" to identify it. Does this make sense ???? |
| ||
You could simply call each door "Door" using nameentity.nameentity Door, "Door" Then to determine whether an entity is a door use .. If entityname( Entity ) = "Door" Do Something Endif |
| ||
it depends on how you storing your doors, say your using types add an extra field for its door id. if your using arrays then add a extra element to your arrays index. *EDIT, i see you dont want to use types. how about arrays. or you could do as Stevie G points out, using types or arrays would make your group'd objects more flexible. kev |
| ||
You might find this useful: http://www.blitzbasic.com/codearcs/codearcs.php?code=1970 Ive made it so you can just copy and paste it (no media reqd) In the example, im creating d1, d2 etc manually but you could always add a create door function for a more complex system. You can modify it to use camerapick to open them with a small mod: Where pickedmesh is the picked entity handle: ;NOTE! for this to work you need to set: ;entitypickmode d\door,2 ;when creating the door!!! ;replace the lines: ; If KeyHit(2) D1\ACTIVATE=1 ; If KeyHit(3) D2\ACTIVATE=1 ;with the following: pickedmesh=camerapick(mousex(),mousey()) Updatedoors(pickedmesh) ;then add this to door func to functions area (or for the more advanced, incorporate it into upddatealldoors!): Function updatedoors(pickedmesh) For d.doormesh=Each doormesh if pickedmesh=d\door ;was door clicked on? if entitydistance (hero,d\door) < 50 ;so you gotta be close ;you could always but another condition in here for if player has d\key (for example) ;) d\activate=1 exit endif endif next end function |
| ||
Storing the mesh handle in the entity name will mean you don't have to loop through all the doors to find the one you picked .. this is more efficient if you have alot of doors ...d.doormesh = new doormesh d\door = createcube() nameentity d\door, handle(d) ;add this to door functions: Function Updatedoors(pickedmesh) d.doormesh = Object.doormesh( EntityName( pickedmesh ) ) If d <> Null If EntityDistance (hero,d\door) < 50 d\activate=1 EndIf EndIf End Function |
| ||
WAAAAAAAAAAAAAAH!!???!! :O Damn, all this time i have been praying mark would implement some kind of lightning fast record search & return function, and here it is all along!! When did this "Object" thing get implemented??? Ive not seen it before! Its not in the manual either :O learn something new every day :) Thx for the tip. (im now off to modify every program ive ever written :/ ) |
| ||
theres lots of thinks like this im sure ive missed. ive just ordered the new manual hoping it will fill me in on some of these. |