I think I found a bug
myfile.ash
enum EnumState {
eES_False = 0,
eES_True = 1,
};
struct Foo{
protected EnumState _state;
import attribute EnumState public_state;
};
Foo bar;
myfile.asc
FindoutStateEnum get_public_state(this Foo*){
return this._state;
}
void set_public_state(this Foo*, EnumState value){
this._state = override;
}
Trying to read bar.public_state get's me zero - elsewhere or in the same file (using bar.get_state()).
I guess I shouldn't declare the instance bar of Foo in the .ash, but I wanted something akin to a global singleton.
My solution was to change myfile.asc to
int local_state;
FindoutStateEnum get_public_state(this Foo*){
return local_state;
}
void set_public_state(this Foo*, EnumState value){
local_state = override;
}
---
Edit: CW solved below.
myfile.ash
Foo bar;
This is not a global instance, this is multiple instances, one per every script that includes a header.
You did not tell how did you set and get values. But e.g. if you use setter in one script and getter in another script, then you will work with two separate objects of Foo.
This is why you should not put variables in header like that, only use "import".
EDIT:
If you want to make a "singleton" in AGS:
* have only static functions and static attributes in a struct.
* have actual data hidden inside a module.
Only for the sake of example, I usually make second struct inside module called FooData and store actual data there.