


Raven
/** * Serializes an object to a file (object pointers to non-always loaded objects are not supported) * * @param Obj The object to serialize * @param Pathname The path to the file to save * @param bIsSaveGame If TRUE, FILEWRITE_SaveGame will be used to create the file writer * @param Version A version number to save with the archive, so that we can safely fail when loading old versioned files * * @return TRUE if successful */ native static final function bool BasicSaveObject(Object Obj, string Pathname, bool bIsSaveGame, int Version); /** * Loads an object from a file (saved with the BasicSaveObject function). It should already be * allocated just like the original object was allocated * * @param Obj The object to serialize * @param Pathname The path to the file to read and create the object from * @param bIsSaveGame If TRUE, FILEREAD_SaveGame will be used to create the file reader * @param Version A version number to match with the version saved in the archive, so that we can safely fail when loading old versioned files * * @return TRUE if successful */ native static final function bool BasicLoadObject(Object Obj, string Pathname, bool bIsSaveGame, int Version);
gameState = new class'DH_GameState'; gameState.VOne = 10; gameState.VTwo = 10; gameState.VThree = 10; //Then I call this: class'Engine'.static.BasicSaveObject(gameState, "state.bin", true, 0);
class DH_GameState extends Object; var float VOne; var float VTwo; var float VThree; DefaultProperties { VOne = -1 VTwo = -1 VThree = -1 }
gameState = new class'DH_GameState'; if(class'Engine'.static.BasicLoadObject(gameState, "state.bin", true, 0)) { currentVOne = gameState.VOne currentVTwo = gameState.VTwo currentVThree = gameState.VThree }
var float currentVOne, currentVTwo, currentVThree; //... exec function TestSaveGame() { local DH_GameState GameState; GameState = new class'DH_GameState'; `log("GameState's initial values:"@GameState.VOne@GameState.VOne@GameState.VOne); `log("PlayerController's values:"@currentVOne@currentVOne@currentVOne); GameState.VOne = currentVOne; GameState.VTwo = currentVTwo; GameState.VThree = currentVThree; `log("Saving GameState's values:"@GameState.VOne@GameState.VOne@GameState.VOne); class'Engine'.static.BasicSaveObject(GameState, "state.bin", true, 0); } exec function TestLoadGame() { local DH_GameState GameState; GameState = new class'DH_GameState'; `log("GameState's initial values:"@GameState.VOne@GameState.VOne@GameState.VOne); if(class'Engine'.static.BasicLoadObject(gameState, "state.bin", true, 0)) { `log("Load successful, old values:"@currentVOne@currentVTwo@currentVThree); currentVOne = gameState.VOne; currentVTwo = gameState.VTwo; currentVThree = gameState.VThree; `log("New values:"@currentVOne@currentVTwo@currentVThree); } else { `log("Load failed, values anyway:"@GameState.VOne@GameState.VOne@GameState.VOne); } }
[0008.74] ScriptLog: GameState's initial values: -1.0000 -1.0000 -1.0000 [0008.74] ScriptLog: Load failed, values anyway: -1.0000 -1.0000 -1.0000 [0009.38] ScriptLog: GameState's initial values: -1.0000 -1.0000 -1.0000 [0009.38] ScriptLog: PlayerController's values: 0.0000 0.0000 0.0000 [0009.39] ScriptLog: Saving GameState's values: 0.0000 0.0000 0.0000 [0010.08] ScriptLog: GameState's initial values: -1.0000 -1.0000 -1.0000 [0010.08] ScriptLog: Load successful, old values: 0.0000 0.0000 0.0000 [0010.08] ScriptLog: New values: 0.0000 0.0000 0.0000
..\..\MySaveDirectory\MySaveGame.USX
Comment