Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unreal Development Kit Game Programming with UnrealScript: Beginner's Guide

You're reading from   Unreal Development Kit Game Programming with UnrealScript: Beginner's Guide Create games beyond your imagination with the Unreal Development Kit

Arrow left icon
Product type Paperback
Published in Dec 2011
Publisher Packt
ISBN-13 9781849691925
Length 466 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Rachel Cordone Rachel Cordone
Author Profile Icon Rachel Cordone
Rachel Cordone
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Unreal Development Kit Game Programming with UnrealScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Project Setup and Test Environments FREE CHAPTER 2. Storing and Manipulating Data 3. Understanding the Class Tree 4. Making Custom Classes 5. Using Functions 6. Using States to Control Behavior 7. Working with Kismet 8. Creating Multiplayer Games 9. Debugging and Optimization 10. Odds and Ends Pop Quiz Answers Index

Time for action – Using arrays


  1. Change our variable declaration line to this:

    var int Baskets[4];

    This will create an array of four baskets. That's easy enough, but how do we change their values?

  2. In our PostBeginPlay function, add these lines:

    Baskets[0] = 2;
    Baskets[1] = 13;
    Baskets[2] = 4;
    Baskets[3] = 1;

    One important thing to remember about arrays is that they start at 0. Even though we have 4 elements in our array, since it starts at 0 it only goes up to 3. If we tried to add a line like this to our function:

    Baskets[4] = 7;

    We would get an error.

  3. Let's go ahead and add the line to see what happens. It will compile just fine, but when we test it in the game we will see the error in the log file:

    [0007.53] ScriptWarning: Accessed array 'AwesomeActor_0.Baskets' out of bounds (4/4)
       AwesomeActor UEDPCAwesomeMap.TheWorld:PersistentLevel.AwesomeActor_0
       Function AwesomeGame.AwesomeActor:PostBeginPlay:0046

    The out of bounds error lets us know that we tried to access an element of the array that...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image