Yes, attributes (aka properties) are syntactic sugar over get/set functions.
Compared to a get/set pair they provide a single "attribute" name used for both get and set:
// functions
object.SetValue(new_value);
int value = object.GetValue();
// attribute
object.Value = new_value;
int value = object.Value;
Attributes combine variable syntax and abilities of a function.
Like variables, attributes may use assignment operators, including combined operators like += or ++:
object.Value++;
object.Value -= 10;
Like functions, attributes may have side effects (additional processing hidden behind them), they don't have to have a strict field associated with them. You may have a single attribute that changes multiple data on assignment, or multiple attributes that write or read same data in different ways.
You do not have to declare get_ and set_ functions in the struct. You may omit these, and then define them inside a script body as extender functions. That will save amount of code for the struct declaration.
This is also explained in the manual: https://adventuregamestudio.github.io/ags-manual/OOProgramming.html#access-with-extender-functions
Quote from: yarooze on Tue 10/12/2024 14:21:232. what is this "this" injection for?
The "this" in parameter list is used in
extender function declaration only in order to tell which struct this function belongs to.
https://adventuregamestudio.github.io/ags-manual/ExtenderFunctions.html
If you write a function which was declared in a struct, then you use "Struct::Function" syntax, and you don't have to use "this" in parameter list, since compiler will already know that it belongs to "Struct".
In the example that you post, "void MyStruct" is already declared in the struct, so you use "MyStruct::MyStruct" syntax when writing its body.
But function "get_Data" is not declared in the struct, so you use extender syntax "get_Data(this MyStruct*)" in order to tell that this belongs to MyStruct.
In AGS 3 you must use "this." always in member functions. In AGS 4 the new compiler allows to omit "this."
However there's currently a problem in case member name matches global variable. IIRC in such case a global variable will take priority. So you better use "this.". We have a issue ticket opened for this reason:
https://github.com/adventuregamestudio/ags/issues/2067#issuecomment-1660533516
Thank you, Crimson Wizard. No questions left for this topic. (https://i.postimg.cc/DwVbxVf6/good.gif)