RSS

UnrealScript: Kismet Nodes Part Two – Simple Variable Links

17 Apr

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.

Advertisements
 
6 Comments

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

 

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

6 responses to “UnrealScript: Kismet Nodes Part Two – Simple Variable Links

  1. MikeP

    09/03/2012 at 9:54 AM

    Hey good tutorials on scripting some simple nodes. I am in the process of learning how to write them myself. Currently I am trying to make a node that will make a light(or object) rotate when triggered. Having a bit of trouble getting it to work thus the reason I found your site. Trying to do a bit of searching to see if anyone else has a solution or possible similar node already.

     
    • danhaddad

      10/03/2012 at 5:30 PM

      Hello Mike

      Glad these were of help. As for what you are trying to do, it shouldn’t be too difficult, just pass the object to your sequence node and when activated mess with its rotation. Although I would strongly suggest you do this using Matinee, in Matinee you can animate things (rotate, translate…etc) very easily and trigger them using kismet. It all depends on where you want to go with this though.

      Best of luck!

       
      • MikeP

        11/03/2012 at 3:17 AM

        Yeah last month I made a Kismet sequence where I animated lights to simulate cop car emergency lights. This very quickly grew into a big sequence of nodes from triggers to toggles and multiple lights with different values. So this month I wanted to script my own light that would change colors on its own (which I have done), but now I want it to spin/rotate in a circle simulating the cop car emergency lights type movement. I wanted to make it a node so that I could simply hook my colr changing light directly to that one node to accomplish the same effect I did last month with just one node&one actor. Mainly just to learn and see if I could pull it off. I understand it’s probably really easy but I am just learning so I don’t know all the code to make it possible. I messed around with several setups from Vectors to quterions set rotation each with no luck.

         
  2. danhaddad

    11/03/2012 at 9:36 AM

    Well that sounds interesting, best of luck with that! I don’t think you would need quaternions though, Unreal has its own rotation struct called “Rotator” (any actor’s Rotation variable is a Rotator) that takes 3 values, pitch roll and yaw. These guys are in Unreal Rotation Units though so to change them to degrees or radians you need to use the “UnrRotToDeg” or the “UnrRotToRad” to convert them (there are others to convert back).

    So I’d say, get the rotation, do the necessary calculations (if you want it to rotate like a police light, I’d guess you would be messing with the Yaw mostly) then set it back by (YourItem).SetRotation().

    But now this all depends on what you are extending initially and what type of object it is, so it comes down to how your code is structured in the end.

    Best of luck with it, wish I could help more but a little tied up with Min these days.

     
  3. mobile web design chicago

    07/05/2013 at 10:09 AM

    I blog often and I really appreciate your information.
    Your article has truly peaked my interest.
    I’m going to book mark your website and keep checking for new details about once a week. I opted in for your Feed as well.

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: