Code: Select all
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;
}
}
- 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.
Tested in GZDoom g3.7pre-281-gf11b20122, g3.7pre-283-g1b82e2078