RSS

Tag Archives: Kismet

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!

Advertisements
 
2 Comments

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

 

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: , , , , , , , , , , ,