Object() command?
Blitz3D Forums/Blitz3D Programming/Object() command?
| ||
Hi! I have references to an "Object()" command in this forum, but I can't find any documentation on it. Is there an Object() command and if so, what does it do? If there is such a command, where is it documented? Thanks. |
| ||
It's undocumented (on purpose), but you can search the forums for it (and its counterpart Handle) because many others have asked the same question. For all intents and purposes, Handle converts a custom type to an Int, and Object converts it back. That's it without details, anyway. |
| ||
Thanks. I searched the forums and found no definition for it. Is my search technique faulty? I put "Object" into the search box under Blitz3d and read each and every post that was displayed. Is there something else I could have done? Note: I do see that after clicking "Search" a message is displayed "Search All Forums" that appears to be misleading as I get different results if I start by clicking a different "Search" link. Thanks again. |
| ||
Oops, mouse bounced, no post here. |
| ||
Okay, where are those details? Inquiring minds and all that. Thanks. |
| ||
Do you understand types? Because if not, the Object command won't be useful to you. Object and Handle are for more advanced use of types. |
| ||
Yes I understand types very well. I have done various things such as programming a massively scalable cluster manager for a commercial game site - I am just new to Blitz and obviously, am ignorant about undocumented and hard-to-find information. |
| ||
A few tests show how Handle() and Object.myType() operate. Thanks for your help. |
| ||
Well here ya go. Let's say you you have a "creatures" type and create an instance of that type, like so: critter.creatures = New creatures You can now use Handle to get the memory address for that type instance. The most common reason for this would be to make that memory address the name of the entity associated with that type instance, like so: NameEntity critter\entity,Handle(critter) Now you can use Object to get back to the type instance using the memory address. And because you made the memory address the name of the entity, you can work backward to the type instance from the entity (useful in situations like if you want to access the information in the fields of the type instance for an entity collided with:) instance.creatures=Object.creatures(EntityName(collidedEntity)) |
| ||
Regarding the search feature, it's not very intuitive and certainly not as functional as it could be. The former because each search link only applies to the its respective "super" category (e.g. programming, miscellaneous, etc), and the latter because it only searches for a single keyword or phrase (no boolean expressions, etc). I did a search in the Programming forums for "handle and object" and got some results, of which this is one promising thread: http://www.blitzbasic.com/Community/posts.php?topic=29160 Almost more promising would be to browse the forum message titles and search for "handle" or "object" on each page. Or, you could try googling the blitzbasic site. That's probably the best method. |
| ||
hi, martonic I'm using the German version of the B3D IDE help. It contains quite a bit of info about "object", "handle", types and so on (with examples and everything). You can find it on the German blitz site www.blitzbase.de. There is also an online version of that stuff for all of them commands you need. For myself I use object and handle to find out which type-instance a (maybe campicked) mesh belongs to. example: 1. type def type ship field mesh field otherstuff end type 2. creating a type-instance ship1.ship = new ship ship1\mesh = loadmesh("meshfile.b3d") nameentity ship1\mesh, handle(ship1) ;this is point a) 3. picking a mesh with mouse picked = camerapick(mycamera, mousex(), mousey()) 4. identify associated object if picked <> 0 tmpship.ship = object.ship(entityname(picked)) ;this is point b) endif now what you've got in tmpship is the userdefined ship object that belongs to the mesh you picked with the mouse. This is what I do with object and handle, I guess there's a whole lot of more usefull things to do with it... |
| ||
You can now use Handle to get the memory address for that type instance. Sorry to be a pedant but that's not quite true. Handle doesn't return a pointer (memory address), it simply returns a number which are issued sequentially. i.e. the first time you call handle it'll return 1, the next time you call it (on a different type instance) it'll return 2, etc. I quess it's a bit like checking your coat in in a cloakroom where the attendant gives you a number so you can retieve it later. Because the same number is never issued again for the duration of the program (even if you delete the type instance), it would be possible to write some shoddy code that would cause handle to eventually run out of numbers to issue. Granted, this would have to be some very shoddy code (creating and deleting large amounts of types, frequently), and it would have to be running for some time. Never the less, the possibility still remain and this (I'm guessing) is the reason why Handle/Object are not officially supported. Bah, rambled a bit there. :P Anyway, I seem to remember there was some more detailed info on the Handle/object over at Blitzcoder. |
| ||
Oho. I've been using a search through all objects to see which one has the entity handle my pick commands return. Was not thrilled about that but was unaware of anything better... Thanks! |
| ||
@big10p: Interesting. I didn't know that. I actually have some code which would run into that error eventually. I'm not creating/deleting large amounts of types frequently, but I am creating/deleting types and the program is meant to run coninuously basically forever. I guess I should rewrite the code to recycle type instances. @martonic: That's a pretty good method actually. Using Handle and Object is more elegant code certainly, but the brute force method of cycling through all objects is generally so fast that there's no real difference in terms of execution. |