Hi!
I'm a little bit confused with the struct attributes.
1. What is the point to use them instead of simple fields and methods? Only to mask getter/setter?
Here are the examples from the doc.
With attribute:
Code: ags
Without:
Code: ags
The example without attribute is shorter but makes the same, or am I missing something?
2. what is this "this" injection for? To access fields without "this."? But there is no injection in the constructor, but "_data" is called without "this.". Can I inject "this" into simple getter and access protected fields? How can I access a global variable with the same name?
Code: ags
I'm a little bit confused with the struct attributes.
1. What is the point to use them instead of simple fields and methods? Only to mask getter/setter?
Here are the examples from the doc.
With attribute:
struct Weapon
{
protected int damage; // this is our actual property to store the damage
import attribute int Damage; // this is our attribute
import int get_Damage();
import void set_Damage(int damage);
};
int Weapon::get_Damage()
{
return this.damage;
}
void Weapon::set_Damage(int damage)
{
this.damage = damage;
}
Weapon *weapon = new Weapon;
weapon.Damage = 10;
Without:
struct Weapon
{
protected int damage;
import int GetDamage();
import void SetDamage(int);
};
int Weapon::GetDamage()
{
return this.damage;
}
void Weapon::SetDamage(int damage)
{
this.damage = damage;
}
Weapon *weapon = new Weapon;
weapon.SetDamage(10);
Display("%d", weapon.GetDamage());
The example without attribute is shorter but makes the same, or am I missing something?
2. what is this "this" injection for? To access fields without "this."? But there is no injection in the constructor, but "_data" is called without "this.". Can I inject "this" into simple getter and access protected fields? How can I access a global variable with the same name?

managed struct MyStruct
{
import void MyStruct(int data); // this is constructor
import readonly attribute int Data;
writeprotected int _data;
};
// script
void MyStruct::MyStruct(int data)
{
_data = data;
}
int get_Data(this MyStruct*)
{
return _data;
}