The following tutorials will show you how to implemnt a complete checkpoint and save based system using C# and Unrealscript. Most functionallity will be in C# to allow complex features which can be called by Unrealscript.
The system will allow:
- The creation of a checkpoint object which will store information that can be used to revert the state of the game to how it was when the checkpoint was created
- An object cache to keep the most recently created checkpoint in memory to increase performance
- Automatic sorting to return the most recent checkpoint to create an "Autoload" system
- Search routines to return checkpoints that reach certain requirments
- Cloning of checkpoints for "Autosave" purposes
- Saving of checkpoints to create a full saving system
- Encyption to stop the player from hex editing the file and cheating
Part one : The checkpoint Object, C#
Please Note: This Section is C# code and must be compiled and referenced through the DLL bind feature of the UDK, Unrealscript intergration will be discussed in a later tutorial
The core of the checkpoint system will focus on the checkpoint object, a class that can take "snapshots" of data and store them to later revert to the state stored. Access classes, known as "caretakers" (Under the "Memento" design pattern, which this system uses) will allow the storage of a single checkpoint object to revert to. "The multi-caretaker" class will allow multiple checkpoints to be saved and restored through the use of an internal Array List
The code for the checkpoint class:
Code:
using system
using system.collections
public class Checkpoint
{
public Checkpoint() {}
public Checkpoint(string Somedata, int Somenumber)
{
//The data that you need to save goes here
this.Somedata = data;
this.Somenumber = number;
}
//Default Values
private string Somedata = "Data";
private int Somenumber = 1;
//Get and Set accessors
public string Somedata
{
get{return(Somedata);}
set{Somedata = value;}
}
public void ChangeSomenumber(int newNumber)
{
Somenumber = newNumber;
}
public void display()
{
//Replace with method to pass values to Unrealscript (Possibly as a structure) - Covered in later tutorial
Console.Writeline("Somenumber: " + Somenumber);
Console.Writeline("Somedata: " + Somedata);
}
//Nested Memento class to save outer class' state
internal class Memento
{
internal Memento(Checkpoint data)
{
this.Somedata = data.Somedata;
this.Somenumber = data.Somenumber;
originator = data;
}
private Checkpoint originator = null;
private string Somedata = "data";
private int Somenumber = 1;
internal void Rollback()
{
originator.Somedata = this.Somedata;
originator.Somenumber = this.Somenumber;
}
}
}
The code for the checkpoint caretaker class:
Code:
public class CheckpointCaretaker
{
private Checkpoint.Memento Savedstate = null;
internal Checkpoint.Memento Memento
{
get{return(Savedstate);}
set{Savedstate = value;}
}
}
The code for the multi-checkpoint cartaker class:
Code:
public class MultiCheckpointCaretaker
{
private Arraylist Savedstate = new Arraylist();
internal Checkpoint.Memento this[int index]
{
get{return((Checkpoint.Memento)Savedstate[index]);}
set{Savedstate[index] = (Checkpoint.Memento)value;}
}
internal void Add(Checkpoint.Memento Memento)
{
Savedstate.Add(Memento)
}
internal int count
{
get{return(Savedstate.count);}
}
}
To be continued...
Bookmarks