Object() command??
Blitz3D Forums/Blitz3D Programming/Object() command??
| ||
Hi, Blitz seems to highlight the Object() command, as if it were a default function. But, it doesnt exists....what's about this? Are we silently going object-oriented, Mark :-P? |
| ||
Handle and Object are unofficial commands. Handle with return a numeric handle to a type. Object will convert the handle number back into a type reference. Handy for GUIs and other type intensive stuff. |
| ||
Hmmmmmm I don't fully understand, but now I know it's an unofficial command :D |
| ||
Say you have a type called fish Type Fish Field colour Field Speed End Type You create a few fish Fish1.FISH = New Fish Fish1\color = 1 FirstFish = Handle(Fish1) Fish1.FISH = New Fish Fish1\color = 2 SecondFish = Handle(Fish1) You now have the handles to the two fish. These could be poked into banks, returned from functions etc. Whatever. Then when you want to reference the type again. FISH1 = Object(FirstFish) You can then access the type as normal. i.e. Fish1\Color = 2. |
| ||
aaaaah that is pretty useful! Thank you for explaining. |
| ||
I have played around with Object/Handle for a while now. At first, I thought the references to the types would change if say, you inserted a new type somewhere or deleted one of the existing ones. The pointers seem to stay the same however: Type fruitTYPE Field name$ End Type Global t.fruitTYPE t=New fruitTYPE : t\name="apple" t=New fruitTYPE : t\name="orange" t=New fruitTYPE : t\name="pear" ShowFruitList t=New fruitTYPE : Insert t After First fruitTYPE t\name="banana" Print "inserted 'banana':" ShowFruitList t=Before Last fruitTYPE : Delete t Print "deleted 'orange':" ShowFruitList in$=Input$("Done ... Press RETURN") End Function ShowFruitList() Print "{" For t=Each fruitTYPE Print "Name: "+t\name+" Handle: "+Handle(t) Next Print "}" End Function |
| ||
That's a very cool explaination Lee :) Thanks, i think i understand now :D |
| ||
what's especially cool is that you can write the type handle to the entityradiusZ property in blitz. then whenever that entity comes up, you can access its associateds type. |
| ||
botbuilder... entityradiusz ??? what do you mean.. do you have an example? |
| ||
This is why I cringe whenever the Object/Handle topic comes up. It invariably leads to baffling pronouncements like this. The entityradiusz thing goes back to another thread about the internal structure of Blitz entities. It was observed that there is, apparently, space reserved for some features which are not currently implemented. So you could use this space to hold something else, such as a handle. That strikes me as asking for trouble. |
| ||
Yeah, it's sort of asking for trouble once entityZ is actually used by blitz :) . Sorry for being confusing. here's some incomplete code. As you can see it is directly peeking and poking blitz's memory. This requires the memory dll. Const entity_radius_Z_offset=240 Type Obj Field typ End Type e=CreateSphere() newo.obj=New obj PokeL e+entity_radius_Z_offset,Handle(newo.obj) ;Now, Say you were camerapicking entities. Here's how you would find out the entities type without iterations. o.obj=Object.obj(PeekL(CameraPick(cam,MouseX(),MouseY())+entity_radius_Z_offset)) |
| ||
I wonder if Mark has considered adding the EntityRadiusZ hack bot builder and Floyd described as a new feature for Blitz (with a more sensible syntax obviously.) It is very useful in many different situations to access a specific type instance based on the entity which has been picked or collided with. Come to think of it, it would be useful if there were just generally several undefined attributes for entities which you can store values in. In other words, exactly the same as the EntityRadiusZ hack but formalized with special commands like EntityAttribute (or something like that.) Then you/we can do stuff like the trick described here but without worrying that the reserved space is suddenly going to be used in a future version of Blitz. |
| ||
could just use nameentity/entityname... |
| ||
yeah... you could use nameentity, but you would have to grab the first for chars and convert it to a integer :( it's just a bit slicker to have a straight int. Agreed definitly. It would be very cool to be able to use the commands that return an entity and quickly acquire a type or just use it as a straight value. how bout an array of values so you can say somthing like: box=createcube() DimEntityArray box,10 entityattribute box,1,5 ;entityattribute entity,index,value |