Reply To: How to create/get properties of groups of data via classes/structs?

FlowCanvas Forums Support How to create/get properties of groups of data via classes/structs? Reply To: How to create/get properties of groups of data via classes/structs?

#1192
Gavalakis
Keymaster

Hey,

It’s not like using one or the other is better and each has pros/cons.
For example properties can not be serialized, but rather only fields can. Properties on the other hand, allow for better code management and extensibility. Purly data based classes or structs (like your Card class case) may not really gain any advantage from using properties and may seem like an extra unnecessary work, but I personally try to use properties with “backing” serializable fields as much as possible 🙂

Say for example you need a health parameter and at a later time in development you also want to to introduce “health buffs”. If “health” was a field, then you are basically stuck with a single value (the value of the health field) and you will have to create extra function like GetTotalHealth() and also change other parts of code to use this new function now.
If “health” was a property though with a backing field “_health”, you could simply change the property getter to return _health + GetHealthBuffs() and you need not worry about changing other parts of your scripts.
A simple example, but I hope it helps clarifies 🙂

By the way, I have just send you an email of the current/latest version of FlowCanvas which includes the ability to read/write to fields directly.

You are very welcome and thanks!

Join us on Discord: https://discord.gg/97q2Rjh