Unreal Development Kit Game Programming with UnrealScript Beginner's Guide Create games beyond your imagination with the Unreal Development Kit Rachel Cordone BIRMINGHAM - MUMBAI Unreal Development Kit Game Programming with UnrealScript Beginner's Guide Copyright © 2011 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: December 2011 Production Reference: 1081211 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84969-192-5 www.packtpub.com Cover Image by Tom Mooney ([email protected]) Credits Author Project Coordinator Rachel Cordone Kushal Bhardwaj Reviewers Proofreaders Edward Davies Mario Cecere Dave Voyles Chris Smith Acquisition Editor Indexer Wilson D'Souza Hemangini Bari Development Editor Graphics Meeta Rajani Manu Joseph Technical Editors Production Coordinator Pramila Balan Arvindkumar Gupta Kavita Iyer Llewellyn Rozario Cover Work Arvindkumar Gupta About the Author Rachel Cordone is a designer and self-taught UnrealScript programmer, who has been working with the Unreal Engine since 1999. She has worked for various game and simulation companies since 2003, including Pipeworks Software and Parsons Brinkerhoff, and has started up her own game company, Stubborn Horse Studios, to make independent games with the Unreal Development Kit. Stubborn Horse's first project, Prometheus, won several awards in Epic Games' Make Something Unreal Contest. I would like to thank my crazy goat for his love and support while writing this book! About the Reviewers Edward Davies is in the final year of his Game Art and Animation degree at the University of Glamorgan. He has a strong interest in game design, particularly the Unreal Development Kit, concept art, and 3D modeling and texturing. More of Edward's work may be seen at www.kungfoowiz.deviantart.com/gallery. Dave Voyles is a Managing Editor and Podcast Producer for Armless Octopus. He covers Xbox LIVE Indie Game, Xbox Live Arcade, and Playstation Network news, reviews, and developer interviews. He holds a BS in Communication Studies from SUNY Oneonta, and is currently attending the New York Institute of Technology to work on his MBA in Management of Information Systems. His additional work within the gaming community includes working as the Coordinator of the Indie Games Summer Uprising, which looks to promote the most outstanding titles on the Xbox LIVE Indie Games platform. Dave is also an Unreal Script programmer for two titles that will be released on PC and iOS, at the end of 2011. Most notably, he is the founder of the New York City-based UDK meetup group, where he works with other developers to collaborate on endeavors in a physical environment, as well as provide tutorials. You can find more of his work by visiting his sites http://www.DaveVoyles.wordpress.com or http://www.ArmlessOctopus.com. www.PacktPub.com Support files, eBooks, discount offers, and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read, and search across Packt's entire library of books. Why Subscribe? Fully searchable across every book published by Packt Copy and paste, print and bookmark content On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Project Setup and Test Environments 7 System requirements 8 Minimum requirements: 8 Time for action – Installing the UDK 8 Directory overview 10 Binaries 10 Development 11 Engine 11 UDKGame 11 Using external programs to code 12 ConTEXT 12 Time for action – Installing ConTEXT 13 Time for action – Configuring ConTEXT 14 UnCodeX 19 Time for action – Installing UnCodeX 19 Time for action – Configuring UnCodeX 20 nFringe 23 WOTgreal 23 Setting up a project 23 Time for action – Setting up AwesomeGame 24 Compiling and testing 30 Time for action – Compiling and testing AwesomeActor 30 A quick note about comments 37 Summary 38 Chapter 2: Storing and Manipulating Data 39 Variables and arrays 39 Booleans 40 Table of Contents Time for action – Using booleans 40 Integers and floats 43 Time for action – Using integers 43 Time for action – Using floats 45 Strings 46 Time for action – Using strings 46 Enums 47 Time for action – Using enums 48 Arrays 50 Time for action – Using arrays 51 Dynamic arrays 53 Time for action – Using dynamic arrays 53 Structs 56 Time for action – Using structs 57 Vectors 60 Time for action – Using vectors 60 Rotators 63 Time for action – Using rotators 64 Variable properties 67 Default properties 67 Time for action – Using the default properties block 67 Editable variables 70 Time for action – Editable variables 70 Config variables 71 Time for action – Creating config variables 71 Common operators 73 Standard arithmetic 73 Time for action – Math! 73 Modulo 75 Time for action – Using modulo 75 Comparisons 76 Time for action – Comparisons 76 Logical operators 79 Time for action – Using logical operators 80 Concatenation 81 Time for action – Concatenation 82 Variable functions 83 Ints 83 Floats 83 Strings 84 Vectors 84 Rotators 84 [ ii ] Table of Contents Flow control 85 If else 85 Time for action – Using if/else 86 For 87 Time for action – Using the for statement 87 While 88 Time for action – Something 88 Do until 90 Switch 90 Time for action – Using switches 90 Return 92 Goto 92 Summary 93 Chapter 3: Understanding the Class Tree 95 What is a class? 96 Time for action – All classes are created equally 96 Inheritance 98 Time for action – Examining inheritance 99 Time for action – Making a custom weapon 100 Time for action – Experiments with inheritance 102 Function overriding 104 Time for action – Creating a custom GameInfo and PlayerController 104 Time for action – Experiments with function overriding 106 Actors as variables 116 Time for action – Experiments with Actors as variables 116 Casting 124 Time for action – Casting Actor variables 124 Time for action – A practical example of casting for our game 129 Summary 134 Chapter 4: Making Custom Classes 135 Creating a class 135 Awesome Game quicky design document 136 Class breakdown 137 Time for action – Creating the weapon branch 137 Class modifiers 147 Placeable 147 Notplaceable 147 Abstract 148 Time for action – Using abstract 148 Native 150 [ iii ]