My program doesn't have bugs. It just develops random features.

UnrealScript Hello World

From Unreal Wiki, The Unreal Engine Documentation Site
Revision as of 10:57, 27 December 2010 by Eliot (Talk | contribs) (Minor corrections)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This tutorial will explain the steps to making your first "Hello, world!" modification; we'll be using a gametype to do our hello world example.

Qualifications[edit]

Getting started[edit]

Before we can begin coding our "Hello, world!" mod, we will have to create a new project folder.

Unreal Engine 1/2 
Browse to path "%HomeDrive%\GAMEDIRECTORY\" and make a new folder named HelloWorld this will be the name of the project and the compiled file name i.e. "HelloWorld.u".
Unreal Engine 3 
Open Windows Explorer and go to path "%HomeDrive%\GAMEDIRECTORY\Development\Src\" and make a new folder named HelloWorld this will be the name of the project and the compiled file name i.e. "HelloWorld.u".

Open HelloWorld and make a new folder named Classes this will be the folder where all UnrealScript classes go to. Now open your favorite TextEditor and start copying the code below:

class HelloWorldGame extends GameInfo;

The above code means this is a class and that the class name is HelloWorld and this class extends the class GameInfo(gametype).

Now to make this class useful we'll have to start overriding specific events that the Unreal Engine will notify our gametype about so that we can actually start doing our thing, copy the code below:

event InitGame( string Options, out string Error )
{
    // Call the parent(i.e. GameInfo) InitGame event version and pass the parameters
    super.InitGame( Options, Error );
 
    // Unreal Engine 1/2
    Log( "Hello, world!" );
 
    // Unreal Engine 3
    `log( "Hello, world!" );
}

The above code tells that this class overrides the event named InitGame(the earliest UnrealScript event of all) that accepts the following parameter Options and optionally return an Error.

"{" means the beginning of this event's scope and "}" the end. The first code is usually a super call which tells the engine to call the parent's version of InitGame before it executes our code e.g. Log*, next we tell the engine call the function named Log with the following message of "Hello, world!".

Now we have to save this as a class file i.e. .uc, in your TextEditor go to File->Save As... and name the file the same as your class name in this case HelloWorldGame and add the extension ".uc", go to your project classes folder e.g. HelloWorld\Classes\ and click Save!

Compiling your modification[edit]

Now to make the code above useful and executable by the Unreal Engine we will have to compile it, which will output a Unreal file named HelloWorld.u

In order to continue we will first have to tell the Unreal Engine which packages to recompile, we do this by adding a Mod/EditPackage:

Unreal Engine 1/2 
Browse to your game directory and go in System\ and open GAME.ini, search for [Editor.EditorEngine] section and below it add EditPackages=HelloWorld, Save the ini file and move on to the next step: Open your favorite TextEditor and copy the code below:
cd.. # step out of project folder
cd System # step into System folder
del HelloWorld.u # delete old HelloWorld.u so that we can surely recompile our mod
ucc.exe Editor.MakeCommandlet
Unreal Engine 3 
Browse to your game directory and go in PREFIXGame\Config\ and open PREFIXEngine.ini, search for [UnrealEd.EditorEngine] section and below it add ModEditPackages=HelloWorld, Save the ini file and move on to the next step: Open your favorite TextEditor and copy the code below:
cd.. # step out of project folder
cd.. # step out of Src folder
cd.. # step out of Development folder
cd Binaries # step into Binaries folder
GAME.exe make


Click File->Save As... and set the file name to Make.bat, browse to your project directory(not in classes!) and Save.

Now browse to this "Make.bat" file and execute it, this batch file will execute all the commands in order automate the compiling process for you! Once done, check if there are any errors, if so double check your code to see if you made any typos or check Compiler errors overview, if not it is time to launch the game you compiled HelloWorld for and open up your console and execute "ShowLog" and "Open MAPNAME?Game=HelloWorld.HelloWorldGame", check in the Log Window if you see "Hello, world!" if so then everything is working and it is time to extend your UnrealScript knowledge to start developing your ideas.