Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Chat / Custom user-defined property inside object ?

Years of Service
User Offline
Joined: 19th Sep 2017
Posted: 12th Jun 2018 21:38
Is there maybe any way to set custom property (string) inside Object that are not related to any specific property of the object? I mean something that does not require pairing of the object ID with external variables for getting more details. I think it sounds vague, maybe I'll try to give an example.

When I do raycast, I may get object ID. Now I can look in the external data (typically array), what the given ID means: a door, wall, exploding barrel, opponent or something else. But it would be much more convenient to set such a simple property directly in the object, for example SetObjectString (obj, txt$) and read it by GetObjectString (obj) or something like that. Such string could even contain the whole set of properties (eg using JSON) if someone need this.

As for now I found GetObjectName(obj), but unfortunately there is no SetObjectName, and the property itself is set from loaded model, which rather prevents its use in the way I described.

Maybe I missed something? If not, it seems to me that adding that would be useful and very simple (just single string field and two functions), and by the way, something like that would also be handy with sprites and texts.
Rich Dersheimer
AGK Developer
Silver Codemaster
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 13th Jun 2018 06:38
If there was a sort of meta-data field on objects, sprites, texts, then the meta-data would have to come from somewhere to start with, presumably when you write the program. Then you would need a way to save the object, sprite, or text, so you could load it back in when the program runs.

You might look at user defined types. A UDT can hold all data about objects, sprites, texts, or anything else, including any custom info you cared to add. One UDT array for your objects, one for your sprites, etc.

So a UDT for objects might look something like

So for each of 10 objects you could put the object ID in the objID of the UDT array, and then put the type into objType, where the type can be 1 for door, 2 for wall, 3 for crate, etc. Like this

User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 13th Jun 2018 08:56 Edited at: 13th Jun 2018 09:00
Rich is right - its really easy to just define your own data structure

This then gives you the option of storing way more than just a single string or integer...

This code should work for objects just needing a single string of metadata ...

Took a whole 8 minutes to write...

Just be wary that you cant necessarily store object and sprite data in the same array easily...mainly as 3d object id's and sprite ids can both share similar values....The id's have to be unique or multiple arrays used.
Years of Service
User Offline
Joined: 19th Sep 2017
Posted: 13th Jun 2018 10:10
Thank you for the answers. These are elegant, simple and useful solutions.

I have experimented a bit in meantime and it seems that I found some sort of alternative without using UDT. Of course, the use of UDT is much more flexible, but in very simple cases I may encode the property of the object directly in the ID.

The advantage is that it does not require searching in additional data structures, but there are also disadvantages - it can only be a simple identifier and this should not be used in parallel with the automatically generated ID of the objects (there may be a conflict above ID 100,000). Anyway, at the moment the use of UDT seems to be the best practice.

Login to post a reply

Server time is: 2018-10-16 19:43:44
Your offset time is: 2018-10-16 19:43:44