Custom Maps & Logic
  • Custom Map Tutorial
    • Custom Map Introduction
    • Your first map
    • Map Navigation
    • Object Selection
    • Object Positioning
    • Object Attributes
    • Shortcuts and Macros
    • Editor Settings
    • Built-in Components Common Errors
    • Map Performance
    • Custom Assets
      • Your first Asset Bundle
      • Asset Bundles in Map Editor
      • Asset Bundles in Game
      • Adding to Asset Bundles
      • Asset Bundle naming
  • Custom Logic Tutorial
    • Custom Logic Introduction
    • Your first script
    • Variables
    • Types
    • Variable Inspector
    • Expressions
    • Conditionals
    • Loops
    • Functions
    • Coroutines
    • Classes
    • Static Classes
    • Components
    • Extensions
    • Cutscenes
    • Static Objects
    • Networking
    • Commenting
  • Reference
    • Static Classes
      • Game
      • Network
      • Map
      • UI
      • Time
      • Convert
      • String
      • Input
      • Math
      • Random
      • Cutscene
      • Camera
      • RoomData
      • PersistentData
      • Json
      • Physics
    • Objects
      • Component
      • Object
      • Character
      • Human
      • Titan
      • Shifter
      • MapObject
      • Transform
      • Player
      • NetworkView
      • Color
      • Vector3
      • Quaternion
      • Dict
      • List
      • Range
      • LineCastHitResult
      • MapTargetable
      • Random
    • Callbacks
      • Main
      • Components
  • Examples
    • Gamemodes
      • Survive
      • Waves
      • Endless
      • Racing
      • Blade PVP
      • Thunderspear PVP
      • Titan Explode
      • Cranked
      • More Examples
    • Components
      • SupplyStation
      • Daylight
      • PointLight
      • Rigidbody
      • NavMeshObstacle
      • Cannon
      • Dummy
      • Wagon
      • Tag
      • KillRegion
      • DamageRegion
      • MovePingPong
      • RacingCheckpointRegion
      • RacingFinishRegion
      • TeleportRegion
      • Animal
      • SignalMover
      • SignalSender
      • More Examples
Powered by GitBook
On this page
  1. Custom Logic Tutorial

Classes

Classes allow you create modular pieces of code, which can be useful for separating custom logic into manageable pieces. In the previous section we explored the Main class, which is a special class that is always initialized and run upon game start. Besides Main, there are several kinds of classes: Normal classes, components, extensions, and cutscenes. For now we will look at the normal class.

class Main
{
    function Init()
    {
        numberPrinter = NumberPrinter();
        numberPrinter.Print(5);
    }
}

class NumberPrinter
{
    function Init()
    {
        Game.Print("Init");
    }
    
    function Print(num)
    {
        Game.Print(Convert.ToString(num));
    }
}

function Init() is called in every class upon creation.

class NumberPrinter declares a new class NumberPrinter, similar to the way we declared the Main class. Since this is a normal class it does not have access to the callback functions that Main has, except for Init().

numberPrinter = NumberPrinter() creates an instance of the NumberPrinter class and stores it in the numberPrinter variable.

numberPrinter.Print(5) calls the Print function on our instance variable. The output of this program is "Init" followed by "5".

Like Main, custom classes can contain their own instance variables and functions.

PreviousCoroutinesNextStatic Classes

Last updated 7 months ago