- Code: Select all • Expand view
class TestInv : Inventory
{
class<Actor> _classField;
readonly<Actor> _instanceField;
override void BeginPlay()
{
Super.BeginPlay();
_classField = 'DoomImp';
}
override bool Use(bool pickup)
{
if (!_classField)
{
Console.Printf("This block is never reached!");
}
else if (!_instanceField)
{
Console.Printf("Instance field is NULL");
_instanceField = GetDefaultByType(_classField);
}
if (_instanceField)
{
Console.Printf("Instance field == %s", _instanceField.GetClassName());
}
return false;
}
}
The following testing procedure demonstrates the buggy behavior:
- Load the example script and go to any map.
- Type "give TestInv" in the console.
- Type "use TestInv" in the console. You will see two messages: "Instance field is NULL", then "Instance field == DoomImp".
- If you type "use TestInv" again any number of times, you will only see the second message each time: "Instance field == DoomImp". This is expected behavior, since the value has been cached in _instanceField and is not NULL anymore.
- Save your game and load the save.
- Type "use TestInv" yet another time. You will see two messages like in the beginning, indicating that _instanceField has been NULLed. This is not expected behavior. _instanceField should have preserved its value.
It appears that at least in the case when an instance is retrieved via GetDefaultByType, it behaves as a transient variable. This implicit behavior is even worse than this kind of thing, since there is no error message indicating that the variable could not be saved. If such instances are not meant to be saved, then please at least add an error message to inform the user that they've done something bad and their code will not work properly.
Tested in GZDoom g3.7pre-281-gf11b20122, g3.7pre-283-g1b82e2078