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

Conditionals

Conditionals allow us to execute blocks of code based on certain boolean conditions. They include if, else, and elif.

Lets take a look at the basic if conditional, which will execute the block if the condition in parentheses evaluates to true.

function OnGameStart()
{
    numPlayers = Network.Players.Count;
    if (numPlayers > 8)
    {
        Game.Print("Too many players!");
    }
}

We can also chain conditionals together by using elif and else. The second elif (else if) block will execute only if its conditional passes and the first conditional failed. The third else statement will always execute as long as the first two conditionals failed.

function OnGameStart()
{
    numPlayers = Network.Players.Count;
    if (numPlayers > 8)
    {
        Game.Print("Too many players!");
    }
    elif (numPlayers > 4)
    {
        Game.Print("Just the right number of players.");
    }
    else
    {
        Game.Print("Too few players!");
    }
}

Conditionals can also use expressions in their check statement.

if ((numPlayers * 2) > 8 || numPlayers <= 4 * 3)
PreviousExpressionsNextLoops

Last updated 7 months ago