2015/01/10

Tutorial: Introduction to Unrealscript

Hi! This is Lussy.

It's been a while since we posted a tutorial. It's time for another one.

I’ll try my best to help you get started with Unrealscript. Don’t worry if you know nothing about scripting: I don’t know anything about other programming languages either! High five!

As a first step, I recommend downloading Notepad++ (here). It’s a simple, easy-to-use software with lots of functions. You’re going to use this to write your scripts. I also suggest you download UnCodeX (here). It will help you immensely. With it, you can browse all the classes in your script folders (a class is a file of script. Classes can be found here: UDK/Development/Src). You need to configure it first, though.
These two software are all I use for scripting (besides the Internet). Oh, and of course, the UDK, but I assume you already downloaded and installed that. Let’s get started then.

If you plan on making a completely custom game, you need to start with a new gametype. I’ll show you how you can create one.
First, you need to decide what kind of game you want. If you want a shooter very similar to Unreal Tournament 3, you can base your scripts off of the UTGame gametype. If you want something entirely different, I suggest you start from scratch: SimpleGame. If you want something in-between: UDKGame. It has some useful functions, but it isn’t as advanced as UTGame.
It is important that you don’t base your game on something you’ll never use: you’ll only make it harder for yourself. The biggest challenge for me is not writing scripts, but understanding all the scripts that already exist. Of course this might not be the case for you. If you’re not sure, just experiment, try out the gametypes on a sample map and decide which is the closest to the game you want to create. You should only choose one, if you try to mix and match, it will lead to disaster (not the good kind. What I mean is that it will not work.). Once you’re done:

Create a new folder for your scripts. Name it something you’ll recognize. Recommended: Make up a short ‘identifier’ for your classes. In my case, this is OLP. All the files you create should have these letters in the front, so you can find them and refer to them easier. I’ll use TG for this tutorial (TutorialGame). Create another folder inside the one you just created and name it "Classes". Create the following empty files inside your "Classes" folder (you can simply open a new file in Notepad++ and save them inside your folder by the name „TG … .uc”, it will take care of the extension):

-TGGame.uc
-TGPlayerPawn.uc
-TGPlayerController.uc


These are the only ones you need for now. The Game class kind of holds your whole gametype together and defines the rules. The PlayerPawn class defines functionality of your pawn: your player(character). The PlayerController class contains (mostly) the rules by which you can move your player character.

Next, you’ll need to have them extend from the gametype you chose. You can do this by editing the previously created files, like so:

TGGame:
class TGGame extends SimpleGame;

TGPlayerPawn:
class TGPlayerPawn extends Pawn;

TGPlayerController:
class TGPlayerController extends PlayerController;


This makes them extend SimpleGame. It's important to note that the class name inside the file must match the file's name.


For UDKGame:


TGGame:
class TGGame extends UDKGame;

TGPlayerPawn:
class TGPlayerPawn extends UDKPawn;

TGPlayerController:
class TGPlayerController extends UDKPlayerController;


For UTGame:


TGGame:
class TGGame extends UTGame;

TGPlayerPawn:
class TGPlayerPawn extends UTPawn;

TGPlayerController:
class TGPlayerController extends UTPlayerController;

   

Now that you’re done, you need to tell the engine to read your scripts when compiling (Compiling = the compiler reads your scripts and converts them into „machine code”). You need to insert a line into the „DefaultEngine” ini file. You can find it here: UDK/UDKGame/Config/DefaultEngine.ini


Find this line: "[UnrealEd.EditorEngine]". This is the part that shows the compiler which scripts to compile. Insert the line "+EditPackages=TutorialGame" after the other ones. Save and quit. 


You’re almost done: Open Unreal Frontend. ( UDK/Binaries/UnrealFrontend.exe ). 


You will find the compile and full recompile buttons there. I recommend you do a full recompile this time, just in case. You won’t need to do this every time, the compiler detects if a script folder has modified files and it will only compile that folder. (If you get random errors or UDK decides to crash randomly or not even start up, do a full recompile. This will inevitably happen sooner or later.)
So, hit full recompile. It will take a few seconds to finish. After it is finished, you can check the log to make sure your files were found and compiled. 


This was an easy step. It will get harder though. The compiler log is the place where all the errors will be displayed. Like this:


If you get an error, the compiler won’t compile further until you fix the error. Warnings won’t stop the process, but you should still fix those, too.

So now your gametype is ready. You can try it out, but at the moment, it won’t differ from the gametype you extended from. This is the tricky part of Unrealscript: the classes are all part of a tree. They all start from Object.uc. This structure, the extending, lets you use all the functionalities of the classes before yours, without having to define them again and making a huge mess. This also means that you’re going to have to know the content of the classes before yours to use them effectively. I suggest you take a tour in UnCodeX. You’ll get an idea of where everything is.

I should mention that scripting is a very tedious process (personal experience), and you will feel like giving up, especially if you never did anything like this before. You need a lot of patience and practice to do well. I stayed up so many nights, fixing errors and glitches and they all made me furious. You just have to remember your goal (like in my case - if I don't do it, nobody will).

I hope this was helpful to you. I plan on making other tutorials as well that will help you actually modify your gametype. Until next time!


If you want to see our other news, check our Facebook and DeviantArt!

No comments:

Post a Comment