RSS

Tag Archives: UnrealScript

Unrealscript Game Programming Cookbook!

Some friends over at Packt Publishing have released another one of their cookbooks and this time it is all about UnrealScript! They sent me a copy and I’ve been reading through it whenever I had a few moments to spare. I have to say it is a pretty good book for people who would like to get into Unrealscript and may not know much about it. The book even refers to the old Dungeon Defense code-base (Trendy FTW!) that was an instrumental help for me when I was starting out a few years ago.

If you are an artist or a hobbyist and you’ve been wanting to learn UnrealScript I suggest you try this book out as it could be just what you need to get your scripting beak wet.

Also keep an eye on Dungeon Defenders 2, a little bird tells me some interesting things might be happening soon.

 
Leave a comment

Posted by on 12/06/2013 in Recommendations

 

Tags: , , , , , , , ,

Tutorial Requests

Hello Awesome Readers!

I received a lot of good feedback on a bunch of tutorials I wrote, what seems like ages ago… Thanks for stopping by and reading them! Now! I am contemplating what to tackle next so if you guys have anything in particular you need help with leave a comment or drop me a line! Based on your requests I’ll be writing the next tutorial.

Depending on how this goes I’d like to do this more often so share this with anyone you think would be interested and let me know what you think!

 
2 Comments

Posted by on 13/07/2012 in Tutorials, Uncategorized

 

Tags: , , , , , , , ,

Min: A Space Adventure!

This blog has been terribly neglected over the past few months (to all you people who are looking forward to more UnrealScript tutorials I’m sorry it is taking so long, I’ll get to it whenever I have some time to spare =D) but right now I am very pleased to announce:

Min: A Space Adventure!!

Shortly after the Imagine Cup World Finals came to a close, I went on a bit of a development sojourn in Chicago and founded Cwerki Studios! Cwerki is comprised of myself and a handful of very talented people (Michael Taylor and Max Cunningham) and together we set out to build our debut game – Min A Space Adventure.

We recently put together a promotional trailer for the crowd-sourcing site IndieGoGo and the game was received really, really well by the industry and the public. Click here to head to our IndieGoGo site and find out how you can help us bring Min to life!

If you would like to help us out then feel free to do so by contributing and spreading the word about a little planet that seeks to explore the cosmos.

Keep an eye on Cwerki’s official site and make sure to follow me and Cwerki (@Cwerki) on twitter for all the latest!

 
2 Comments

Posted by on 10/11/2011 in Development, Min

 

Tags: , , , , , ,

UnrealScript: Kismet Nodes Part Two – Simple Variable Links

In my previous post I introduced the idea of writing your own Kismet Nodes that would be tailored to your game’s needs. Now I’m going to expand on that and explain how you would use Variable Links for your Kismet Node.

Difficulty: Beginners

This tutorial is aimed at those who know their way around UnrealScript and programming and would like to expand their knowledge concerning a few topics. If you don’t know what UnrealScript is or how to program using it then I suggest you look for a few getting started tutorials before attempting any of this yourself. I will one day write up a few introductory tutorials but for now I’ll stick to selective topics I feel people will most benefit from.

Note: as with most tutorials, code and concepts expressed here are simplified and are meant to serve as a stepping stone for you programming endeavors.

What are Variable Links

Variable links allow you to connect variables to your Kismet Node. Let me give you a simple example. Let us imagine we wanted to write a Kismet Node that takes two integers and adds them up. You would use Variable Links to linkup the 2 variables you want to add together and the variable that will store the result. There is no need to write this since UDK already comes with a handy array of math nodes we can use. Check the image bellow.

UDK's AddInt Node

UDKs AddInt Node

The first thing you should notice is that this node differs from the nodes we wrote in my previous post in that we can connect variable nodes to it through its Variable Links. You might notice a difference in the way the variable links appear. In the image the square links (labeled with a white a) are input links. Input Links allow you to pass variables as input to the node. The triangle links (labeled with a b) are output links. Output Links allow you to write into a kismet variable some result.

So in the image – the two input links are connected to two int variables. It adds them up and spits out the value into the variable connected to the output link.

Scenario

Imagine you wrote some basic functionality that allows the player to gather experience. Your player controller now has something along the lines of:


...
/**How much exp does the player currently have**/
var float currentEXP;
...

and a new function:


/**
* Modifies the player's current exp by adding expGive to it
* @note expGive can be a negative value although will likely never be so
* @param float expGive : how much exp to give/take
**/
function modifyExp(const float expGive)
{
currentEXP += expGive;
}

Note: this is a very primitive exp system and is not one that would go into a game but will be used for the purpose of this tutorial.

Now this is fine if we want to increase the player’s experience within unreal script. But what if you want to award the player for accomplishing a level specific action? For example, let us imagine the player discovered a new area and you want to reward him with 200 experience points how can we allow our designers to modify the player’s experience through kismet?

SeqAct_GiveExp

The obvious answer is to write a Kismet Node that will handle this for us. Create a new .uc file and name it something appropriate. I called mine: DH_SeqAct_GiveExp. Open up your file and (similar to our previous post) extend SequenceAction and write the following:


/**
* This kismet node is used to give the PC exp
* @author : Daniel G Haddad
*/
class DH_SeqAct_GiveExp extends SequenceAction;

var() float expGive;
var float result;

/**
* When activated this node triggers the DH_PlayerController’s modifyExp()
**/
event Activated()
{
local DH_PlayerController PC;

PC = DH_PlayerController(GetWorldInfo().GetALocalPlayerController());
PC.modifyExp(expGive);
result = PC.currentEXP;
}

defaultproperties
{
ObjName=”Reward Exp”
ObjCategory=”DH_PlayerController”

VariableLinks.Empty;
VariableLinks(0)=(ExpectedType=class’SeqVar_Float’,bWriteable = false, LinkDesc=”expGive”,PropertyName=expGive)
VariableLinks(1)=(ExpectedType=class’SeqVar_Float’,bWriteable = true, LinkDesc=”result”,PropertyName=result)
}

Now let me explain what we did. For those of you who read my previous post you will undoubtedly recognize how we got our PlayerController and called the modifyEXP(float) function. Now I will explain all the bits of new code:

var() float expGive;
var float result;

We initialize two variables one called expGive which will hold the amount of experience we would like to give the player. The other is called result and it will be used to hold the total amount of experience the player has after the change.

If you look closely you will notice that one is initialized as var and the other as var(). When we add () to a variable it basically allows us to edit this variable inside the properties box of the object within UDK itself.

For now, save the script and launch the UDK, open up the Kismet editor and place a DH_SeqAct_GiveExp node. If you click on it and dig through its property box you will notice that we can directly input the value of expGive there. This is handy for certain situations. You will also notice that result does not appear there because we initialized it as var and not var(). Refer to the image bellow for clarification:

expGive appears in the properties box

expGive appears in the properties box

Now close the UDK and get back to your code. To explain why we allowed for both expGive to be passed and set think of the following scenarios. Let’s say you simply want to reward the player a static amount of exp when he goes somewhere. You don’t have to hookup a kismet variable, all you would need to do is set the value inside the properties box. Now let’s imagine we want to reward the player experience based on how many kills he has so far or how quickly he did something. In this scenario our exp value would change based on some sort of mathematical function so ultimately we would create a kismet variable that will store the calculated exp value and then pass it to our giveExp node.

Note: if you have a variable connected, that takes priority over the value you set inside the property box.

Now let us check out the activated event:


/**
* When activated this node triggers the DH_PlayerController's modifyExp()
**/
event Activated()
{
local DH_PlayerController PC;

PC = DH_PlayerController(GetWorldInfo().GetALocalPlayerController());
PC.modifyExp(expGive);
result = PC.currentEXP;
}

There is only one line that should seem unfamiliar and that is:

result = PC.currentEXP;

This little bit simply sets the result variable to that of the PC’s currentEXP.

The rest of the code is exactly like my previous post. We initialize a local PC variable, call the modifyExp(float) function with our passed expGive variable.

Note: you might want to run a few checks on the PC to make sure that all is on the up and up, but I won’t include that here for simplicity’s sake.

Finally, all that is left is the defaultproperties code block and it has a few new topics:


defaultproperties
{
ObjName="Reward Exp"
ObjCategory="DH_PlayerController"

VariableLinks.Empty;
VariableLinks(0)=(ExpectedType=class’SeqVar_Float’,bWriteable = false, LinkDesc=”expGive”,PropertyName=expGive)
VariableLinks(1)=(ExpectedType=class’SeqVar_Float’,bWriteable = true, LinkDesc=”result”,PropertyName=result)
}

We’ve already gone through what the first two lines so let us skip over them and focus on the last three.


VariableLinks.Empty;
VariableLinks(0)=(ExpectedType=class'SeqVar_Float',bWriteable = false, LinkDesc="expGive",PropertyName=expGive)
VariableLinks(1)=(ExpectedType=class'SeqVar_Float',bWriteable = true, LinkDesc="result",PropertyName=result)

The first thing I usually do is empty the VariableLinks in this case it won’t make much of a difference but it would come in handy if you try to do something a little advanced with your Kismet nodes so I thought it good to mention it.

Now the other two lines might seem a little intimidating to someone unfamiliar with programming but they are pretty straight forward. All we do here is tell UnrealScript how many Variable Links we want our Kismet Node to have and more importantly we set the properties for each.

So, when we were designing our node we figured we would need one input link that would take the value that we would like to modify the player’s experience by. We decided to take it a step further and have an output link that would then, after adding the value, get the value of the PC’s currentExp variable. This is handy because our node now functions both as a getter and a setter.

VariableLinks(0)=(ExpectedType=class'SeqVar_Float',bWriteable = false, LinkDesc="expGive",PropertyName=expGive)

We tell UnrealScript that in our first Variable Link we expect to see a Kismet Float Variable (the proper class name is: SeqVar_Float). In the next bit we simply set the writeable property to false because we do not intend to write anything into this variable. Finally we give this link a description and in PropertyName we pass the name of the variable we intend to hold the value of this Variable Link.

VariableLinks(1)=(ExpectedType=class'SeqVar_Float',bWriteable = true, LinkDesc="result",PropertyName=result)

Now in our second link the only change is the fact that this time we want this link to be writeable and we make this happen by setting bWriteable = true. We also pass the name of the variable that has the value we would like to write into whatever is connected to this output link. Now save, compile, open up the UDK, and test your new node.

Final Node

How your node should look like and how to use it

So there you have it, you should now be pretty comfortable with creating Kismet Nodes with simple Variable Links. That is it for this week’s tutorial posts. I’m not sure what I’ll go over next week, might be some more introductory topics or I might dive into some advanced topics. Time will tell, until then stay tuned. 🙂

Important Links:

Notes:

If you are writing a multiplayer game or are unsure about whether or not your game will have multiplayer, you can get the player controller using the following method:


event Activated()
{
local WorldInfo wInf;
local DH_PlayerController PC;

wInf = class’WorldInfo’.static.GetWorldInfo();

if (wInf != None)
{
ForEach WI.AllControllers(class’DH_PlayerController’, PC)
{
//Now for each occurrence of DH_PlayerController in your game this section of code will run
PC.something();
…etc
}
}
}

I’ve made a game!

For the past year I’ve formed a small game studio called Cwerki Studios and we’ve been hard at work on our debut game, Min: A Space Adventure! Min built using UDK and was approved by Apple and will become available worldwide on June 18th! Check out our launch trailer!

Click here to download Min for Free from the App Store!

Make sure you like our video and share it with your friends!

It doesn’t end there, Min would not have been possible without the help and support of our community, we have huge, huge plans for Min but more importantly we want to include our community in this future. Head over to our Facebook page and like us to take part in polls and discussions we’ll be orchestrating to decide on Min’s future.

 
6 Comments

Posted by on 17/04/2011 in Kismet Nodes, Tutorials, UnrealScript

 

Tags: , , , , , , , , , , , , , , ,

UnrealScript: Kismet Nodes Part One – An Introduction

Last week I explained how you could save your gamestate using unreal script. For this week’s tutorial post, I thought it would be a good idea to introduce the concept of Kismet Nodes and how we can write our own nodes tailored to our needs.

Difficulty: Beginners

This tutorial is aimed at those who know their way around UnrealScript and programming and would like to expand their knowledge concerning a few topics. If you don’t know what UnrealScript is or how to program using it then I suggest you look for a few getting started tutorials before attempting any of this yourself. I will one day write up a few introductory tutorials but for now I’ll stick to selective topics I feel people will most benefit from.

Note: as with most tutorials, code and concepts expressed here are simplified and are meant to serve as a stepping stone for you programming endeavors.

Kismet Briefly

Kismet is the Unreal engine’s visual scripting language. It allows people who are not familiar with programming to script complex game mechanics and interactions through Kismet. If you do not know what Kismet is or would like learn more about it, two very handy pages on the UDN have everything you need:

I’ll assume you know your way around UDK and its Kismet editor in this tutorial – if you are not familiar with either make sure you take the time to learn the tools before you attempt to do anything with them.

The Scenario

So you are part of a small team working on a game. Your game has multiple levels that the player will progress through. You wrote up your PlayerController, GameMode, and all the necessary classes your game needs. But, your PlayerController has a lot of variables that get saved through a save function. What you want to do is allow your designers some sort of way to save and load these values through Kismet. What you need to do is write a couple of quick Kismet Nodes that when activated, will trigger the save and load functions respectively.

SavePCGameState Node

Now, the best place to start is to get right into programming. If you remember last week we wrote a few functions inside our PlayerController that allowed us to save and load important variables. Now we are going to build upon that by writing a few Kismet nodes that will allow our designers to call on these functions.

Create a new .uc document and call it whatever you like (for organization’s sake you might want to include SeqAct_ before the name of the file I’ll go over what this means in a second). I called mine DH_SeqAct_SavePCGameState. Now open the file and write the following.


/**
* This kismet node is used to trigger the PC to save his stats
* @author : Daniel G Haddad
*/
class DH_SeqAct_SavePCGameState extends SequenceAction;

The first thing you will notice is the following:

extends SequenceAction;

Our script extends from the SequenceAction.uc file which is part of UDK’s source scripts. Kismet nodes have several types (Actions, Events, Conditionals…etc) what we intend to do is create an Action Node. Action Nodes, simply put, are nodes that are written to perform a certain action when you activate them in a sequence chain in the Kismet Editor.

Now fill the rest of your file as follows:


/**
* This kismet node is used to trigger the PC to save his stats
* @author : Daniel G Haddad
*/
class DH_SeqAct_SavePCGameState extends SequenceAction;

event Activated()
{
}

defaultproperties
{
ObjName=”Save PC’s State”
ObjCategory=”DH_PlayerController”
VariableLinks.Empty
}

We didn’t do anything drastic here.


event Activated()
{
}

Here we create the Activated event. Later in the tutorial we will fill the area between the curly braces with the bit of code that will trigger the PC’s save function.

defaultproperties
{
ObjName="Save PC's State"
ObjCategory="DH_PlayerController"
VariableLinks.Empty
}

Now in this bit we initialized some default properties.

ObjName="Save PC's State"
This property gives our node a name to be used inside the Kismet Editor.

ObjCategory="DH_PlayerController"
This property tells the editor what category this node fits under.

VariableLinks.Empty
This bit empties the VariableLinks – more on this later.

Now save your changes – compile your code, open up the UDK, and fire up the Kismet editor (Little green K button).

Right click anywhere in the empty space and navigate through Action. You should find a category called “DH_PlayerController” (or whatever you called your category). Hover over that and a new menu will open up having “Save PC’s State”.

Where your node should be

Navigating to your Kismet Node

If you click your node should appear looking like this.

How it looks so far

The save node

Now there is no sense connecting it since we didn’t program it to do anything yet. Close the UDK and go back to your code and write the following inside the Activate event:

/**
* When activated this node triggers the DH_PlayerController's savePCVariables()
**/
event Activated()
{
local DH_PlayerController PC;

PC = DH_PlayerController(GetWorldInfo().GetALocalPlayerController());

PC.savePCVariables();
}

Firstly, we create a local variable PC of type DH_PlayerController which is my player controller.

local DH_PlayerController PC;

In the next bit of code we call a function called GetALocalPlayerController() and cast its result into our PC variable.

PC = DH_PlayerController(GetWorldInfo().GetALocalPlayerController());

GetALocalPlayerController() is located inside the Actor.uc class and it has the following description:

/** Return first found LocalPlayerController. Fine for single player, in split screen, one will be picked. */

So this function will return our player controller. This method is fine for any single player game (I’ll demonstrate an example of what you would do if you had a multiplayer game later in this tutorial) so it suits us perfectly for now.

In the next bit of code all we do is call the save function we wrote last week.

PC.savePCVariables();

Ideally, you might want to run a few checks on PC depending on the situation but I left all that out for simplicity’s sake.

So there you have it. Our save node is now ready to be hooked up inside our level. Writing up a load node should now be very easy to do since it follows similar steps so go ahead and write that load node up and then fire up UDK to test it out.

What We Just Accomplished

We knew that the player will be progressing through a set of levels and we would like to carry his state through each one. Using the save and load nodes, our designers can now hook up some very basic Kismet scripts that will load the player’s state in the new level and save it out once the player finishes a level or exits.

A quick example Kismet map is shown bellow:

Sample save Kismet map

How wed use our save node

Example load map

How wed use our load node

So there you have it. By now you should have a much better idea about how to write your own Kismet Nodes. Remember that this is only an introduction, Kismet nodes can be used to do a whole lot of things. In my next tutorial I’ll go over variables/variable links and how they work with Kismet nodes. Stay tuned.

Important Links:

Notes:

If you are writing a multiplayer game or are unsure about whether or not your game will have multiplayer, you can get the player controller using the following method:


event Activated()
{
local WorldInfo wInf;
local DH_PlayerController PC;

wInf = class’WorldInfo’.static.GetWorldInfo();

if (wInf != None)
{
ForEach WI.AllControllers(class’DH_PlayerController’, PC)
{
//Now for each occurrence of DH_PlayerController in your game this section of code will run
PC.something();
…etc
}
}
}

I’ve made a game!

For the past year I’ve formed a small game studio called Cwerki Studios and we’ve been hard at work on our debut game, Min: A Space Adventure! Min built using UDK and was approved by Apple and will become available worldwide on June 18th! Check out our launch trailer!

Click here to download Min for Free from the App Store!

Make sure you like our video and share it with your friends!

It doesn’t end there, Min would not have been possible without the help and support of our community, we have huge, huge plans for Min but more importantly we want to include our community in this future. Head over to our Facebook page and like us to take part in polls and discussions we’ll be orchestrating to decide on Min’s future.

 
 

Tags: , , , , , , , , , , ,

UnrealScript: GameState Save Tutorial

In this tutorial I will explain my method for saving important variables in UnrealScript. All this stuff is pretty straight forward and isn’t all that difficult. I read about it on this page of the UDN but if you would like to see a more practical demonstration then you’ve come to the right place.

Note: this tutorial assumes you have some basic knowledge of how UnrealScript works and also assumes that you have done some programming before. If you need an intro to UnrealScript or intro to Programming tutorial you should look somewhere else as all this might seem confusing at best. This tutorial also assumes you already have a PlayerController class setup.

What we will be using

If you checked out the link above you will notice that UDN mentions three ways to saving data. I obviously opted to use the first approach for a couple of reasons:

  • it works for both UDK and UDK: Mobile
  • it is done in UnrealScript which obviously has a lot of benefits

This approach uses two functions from the Engine class called BasicLoadObject for loading and BasicSaveObject for saving. If you open up the Engine.uc class and look for those two functions you will find this:


/**
* 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);

It is all pretty straight forward – the object “Obj” is saved into “Pathname”, the boolean bIsSaveGame has to be true if you are on the mobile and the final integer number “Version” is used to make sure you load a save for the proper game version. So now what do we do with these functions?

Our attention should focus on Object Obj since it is what will be saved. As the document explains: “… create a single one of these objects to store all of your settings, then save the object” so that should be our first step.

Creating an object to store our

What I opted to do was to put together a class called GameState (extending Object) whose primary purpose would be to store copies of variables I would like to save. Naturally, depending on your game, you might want to construct things differently. But I shall assume that you are writing a simple game that only needs to store variables.


/**
* This class is intended to store and hold all the information we would
* like to save in our game
* @author Daniel G. Haddad
*/

class DH_GameState extends Object;

Let’s say my player controller has the three variables I would like to store:


...
var float highScore;
var float currentLevel;
var float numOfShots;
...

So what I do now is duplicate these variables inside the DH_GameState class so our class will now look something like this:


/**
* This class is intended to store and hold all the information we would
* like to save in our game
* @author Daniel G. Haddad
*/

class DH_GameState extends Object;

var float highScore;
var float currentLevel;
var float numOfShots;

/**
* Here I default the values of the variables.
**/
defaultproperties
{
highScore = -1
currentLevel= -1
numOfShots= -1
}

So now we have our DH_GameState class ready for use.

Now, there are plenty of places you can call the save and load functions but in this tutorial I opted to include the code as part of the PlayerController.

If you already have a PlayerController class then open it up and prepare to add a couple of functions to it.

Our save function:


/**
* This function saves our variables using BasicSaveObject
**/
function savePCVariables()
{
local DH_GameState gameState; //our gameState variable
//Init our gamestate variable - this is important
gameState = new class'DH_GameState';

//Save the variables
gameState.highScore = highScore; //Set the gameState’s highScore to the PC’s highScore
gameState.currentLevel = currentLevel; // etc…
gameState.numOfShots = numOfShots; // etc…

//Call the Engine BasicSaveObject function to save the gameState object
//Version 0: Development
class’Engine’.static.BasicSaveObject(gameState, “GameState.bin”, true, 0);
}

/**
* This function loads our variables using BasicLoadObject
**/
function loadPCVariables()
{
local DH_GameState gameState; //our gameState variable
//Init our gamestate variable – this is important
gameState = new class’DH_GameState’;

//Load the variables gamestate using BasicLoadObject
//Version 0: Development
if(class’Engine’.static.BasicLoadObject(gameState, “GameState.bin”, true, 0)) //Load only if the file actually exists
{
highScore = gameState.highScore; //Set the PC’s highScore to the value we loaded
currentLevel = gameState.currentLevel; // etc…
numOfShots = gameState.numOfShots; // etc…
}
else
{
`Log(“File not found while loading PC’s variables”);
}
}

Now whenever you need to save your variables simply call the savePCVariables() function and whenever you want to load call the loadPCVariables() function.

How they work

Saving:

local DH_GameState gameState; //our gameState variable
//Init our gamestate variable - this is important
gameState = new class'DH_GameState';

We first initialize a DH_GameState object called gameState. We tailored this class to have the variables we want to save so this object will store the variables we would like to save inside it…


//Save the variables
gameState.highScore = highScore; //Set the gameState's highScore to the PC's highScore
gameState.currentLevel = currentLevel; // etc...
gameState.numOfShots = numOfShots; // etc...

…and then we move on to populating it (gameState object) with the values we want to save.


//Call the Engine BasicSaveObject function to save the gameState object
//Version 0: Development
class'Engine'.static.BasicSaveObject(gameState, "GameState.bin", true, 0);

Finally, with everything ready, we call the Engine’s BasicSaveObject function and pass gameState to it as the object.
I chose to save the info in a file called “GameState.bin”.

Loading:


local DH_GameState gameState; //our gameState variable
//Init our gamestate variable - this is important
gameState = new class'DH_GameState';

Just as we did above, we initialize our gameState object that we will use to load the information into.


//Load the variables gamestate using BasicLoadObject
//Version 0: Development
if(class'Engine'.static.BasicLoadObject(gameState, "GameState.bin", true, 0)) //Load only if the file actually exists

We now load the saved information from the same file name we wrote into only this time the function is inside an if statement. This is done to check if the file exists because, as you might have noticed, the function BasicLoadObject returns a boolean that tells you whether or not the load was successful.


{
highScore = gameState.highScore; //Set the PC's highScore to the value we loaded
currentLevel = gameState.currentLevel; // etc...
numOfShots = gameState.numOfShots; // etc...
}

Now we put into the PC’s variables the values we just loaded into the gameState object.


else
{
`Log("File not found while loading PC's variables");
}
}

And finally we print out some message in case the load fails. I assume that the error was because the file was not found.

So there you have it. Now you have two functions that will save and load the important variables you specified. If you want to add more variables all you need to do is:

  1. Add the variables inside the DH_GameState class
  2. Go over your save function and add the code needed to set the gameState variable value before saving
  3. Go over your load function and add the code needed to set the value of the PC’s variable based on the loaded gameState value

Now I’ll later write up a tutorial that creates a couple of Kismet Nodes that when activate call these two functions. This can be very handy as it will allow you to save and load important variables at key points during your levels. But that’s all for now.

Important Notes

  • Calling BasicSaveObject on a file that already exists will overwrite it
  • The default location for the files will be under your: UDK\UDK-20XX-XX\Binaries\WinXX folder
  • This function will create directories when requested and it will also use relative directory commands like: ..\..\MySaveDirectory\MySaveGame.USX (Solid Snake)

I’ve made a game!

For the past year I’ve formed a small game studio called Cwerki Studios and we’ve been hard at work on our debut game, Min: A Space Adventure! Min built using UDK and was approved by Apple and will become available worldwide on June 18th! Check out our launch trailer!

Click here to download Min for Free from the App Store!

Make sure you like our video and share it with your friends!

It doesn’t end there, Min would not have been possible without the help and support of our community, we have huge, huge plans for Min but more importantly we want to include our community in this future. Head over to our Facebook page and like us to take part in polls and discussions we’ll be orchestrating to decide on Min’s future.

 
17 Comments

Posted by on 08/04/2011 in Tutorials, UnrealScript

 

Tags: , , , , , , , ,