noob question, object properties.

MrEgorize

Member
so i was wondering, how to assign "properties" to objects.
what i mean by that:
for example, i have Player, who is colliding only with obj_solid. So, to add different kinds of solid platforms, i create an object as a child for obj_solid, so that player will collide with all of them. but that is not a good way of doing that because now i need multiple properties for an object, for example i need it to be solid, and breakable. but i can only make this object to be a child of obj_solid OR obj_breakable, so assigning multiple properties this way is impossible. can you please suggest me a good way to assign multiple properties to objects, so that when i write a code, i can easily reference all the solid objects, or all the breakable objects, and have objects that is solid and breakable at the same time?
sorry for bad english and thanks in advance = )
 
You could use the new tag system. Tag objects with strings that denote the properties you want and then check the tags of the object during collision/whatever other interaction you need properties for.
 

kburkhart84

Firehammer Games
but i can only make this object to be a child of obj_solid OR obj_breakable,
OR if all breakables are solid, make the breakable a child of solid, then make any breakable solids a child of THAT object. Not all things fit like that, but for the ones that do, just add another level in hierarchy.

You could also make a variable that all these objects hold(as an alternative to the tag system). You can make an enum to hold the different types, or you can make a few macros instead. Note that this variable can hold an array, which can then store multiple values for the different properties you are looking for. Then, any time you need to access that, you can simply access that variable.
 

Gizmo199

Member
You could also just check that a variable exists. So for example you could have "breakable=true" and then in you player object or whatever when you collide you can just do:

GML:
// COLLISION with obj_breakable
if ( variable_instance_exists(other,"breakable") ){
    // Break other object
}
However the tag system works too. The tag system will only work for a object indexes though. If you wanted say 1 instance of 'obj_breakable' to not be breakable you might want to instead use the 'variable_instance_exists' method.

Tags can be accessed using asset_has_tags()
 

Nidoking

Member
if ( variable_instance_exists(other,"breakable") )
Gross. What's wrong with "breakable = false;" if you want it not to be breakable, and then instead of using reflection, you just check the value of the variable using normal logic?

Not kidding, I commonly make an object to be the uber-parent of everything, just so I can ensure that all of the variables are defined to sensible defaults, and the children can change what they need to change.
 

Gizmo199

Member
Gross. What's wrong with "breakable = false;" if you want it not to be breakable, and then instead of using reflection, you just check the value of the variable using normal logic?

Not kidding, I commonly make an object to be the uber-parent of everything, just so I can ensure that all of the variables are defined to sensible defaults, and the children can change what they need to change.
In that case, you could just not include 'breakable' as a variable in the object and problem solved. :p It's not the ultimate solution, just 1 way to do it. The tag system works better (imo) than parenting since parenting can get REALLY messy if you aren't careful. Too many 'if/or' cases to try and debug/track down. You could easily do your method too (breakable = true/false) and that is also an acceptable way to do it. I personally just find it easier to have an object acknowledge that a breakable variable exists or not. It's definitely not a perfect solution either. Just how I like to do it with *certain* objects/use-cases. For instance, if I am using a custom collision system using structs it's much easier for me to check that a colliding instance contains a struct by checking 'if ( variable_instance_exists(other, "__vCollisionStruct") )". To each their own. I like it, but it's definitely not the end-all-be-all solution by any means. The best solution is to probably have totally separate objects for 'breakable' and 'non-breakable' IMO or tags. :p
 

Nidoking

Member
I use tags for certain things, but I think the interface for using tags in code is clunky. (It makes sense for such a general concept, but that makes it much less useful for things that a more type-specific construct might do.) It also requires you to individually tag each thing you create that needs to have that tag, because tags aren't inherited. Parenting incorporates a lot more than just variables, and it's how you scope with blocks. You can also use it as a contract - if my obj_solid parent defines a "breakable" variable, then I never need to ask whether that variable exists. Anything that is an obj_solid has a value for that variable, and I can just use it and be confident that it has been defined correctly and meaningfully.

If you find that parenting is messy, then you are using parenting incorrectly or designing your games poorly.
 

kburkhart84

Firehammer Games
I honestly wish they would support multi-inheritance...so an object could inherit from multiple parents. It does mean that they would have to design a way to determine which event gets ran in cases where multiple parents have the event, or they could default to doing them in an undocumented order unless manually defined in the object inspector/editor. I think the object inheritance system is a really nice way to organize a hierarchy of objects in many cases, but without multi-inheritance it simply can't fit all use cases.
 
Top