Say I have a unit, and I want to access a data member from another unit, for example this data member can be "Credits" in this following unit
unit SomeUnitToAccess like GeneralUnit {
Credits : uint;
keep Credits == 64;
};
unit SomeUnit like GeneralUnit {
Var1 : uint;
keep Var1 == <Var from another Unit>;
};
I want Var1 to be equal to Credits for example. I couldn't find an example for that in the docs.
Help would be appreciated, thank you!
one way would be using 'static field'. with static field you don't need to know where an instance of this type exists.
unit SomeUnitToAccess like GeneralUnit {
static Credits : uint = 64;
};
unit SomeUnit like GeneralUnit {
Var1 : uint;
keep Var1 == value( SomeUnitToAccess::Credits);
};
but static fields cannot be randomized, only assigned procedurally (like done here, in the field definition. or - in procedural code. for example - in pre_generate).
if you can't use static field, if you must randomize the Credits field, you can have a point in the SomeUnit, to an instance of SomeunitToAccess. then, should constrain this pointer. if this is difficult, if you cannot know where SomeunitToAccess is instantiated, there are ways to find it. but assuming you know, then the code would be
unit SomeUnit like GeneralUnit {
SomeUnitToAccess_p : SomeUnitToAccess;
Var1 : uint;
keep Var1 == SomeUnitToAccess_p.Credits;
};
extend sys {
SomeUnitToAccess is instance;
SomeUnit is instance;
keep SomeUnit.SomeUnitToAccess == SomeUnitToAccess;
};