Skip to content

typeName

ffredyk edited this page Jul 23, 2026 · 1 revision

typeName

Category

Type / Introspection

Arity

UnarytypeName <value>.

typeName <any>

Description

Returns the type name of a value as a lowercase string. Useful for runtime type checking and debugging.

Value type Returns
Number "number"
String "string"
Array "array"
Code "code"
Boolean "boolean"
Nil "nothing"
HashMap "hashmap"
Namespace "namespace"
ScriptHandle "scripthandle"
Error "error"
Shared "shared"

How It Works

Reads the internal type tag from the value's wrapper struct and returns the corresponding string. O(1).

Usage

typeName 42;                   // "number"
typeName "hello";              // "string"
typeName [1, 2, 3];            // "array"
typeName { sleep 1; };         // "code"
typeName true;                 // "boolean"
typeName nil;                  // "nothing"
typeName createHashMap;        // "hashmap"

Type guard

if (typeName _val != "number") then {
    systemChat "Expected a number";
};

Polymorphic dispatch

switch (typeName _input) do {
    case "number": { processNumber(_input); };
    case "string": { processString(_input); };
    case "array":  { processArray(_input); };
    default       { systemChat "Unknown type"; };
};

Validation helper

_assertType = {
    params ["_val", "_expected"];
    if (typeName _val != _expected) then {
        throw f"Type mismatch: expected {_expected}, got {typeName _val}";
    };
};

Thread Safety

ReadOnly — pure query. Safe from any scheduler.

See Also

  • isNil — nil check
  • isNull — null/resolved check
  • str — value to string
  • params — typed destructuring

SQ# Wiki

Home

Engine Docs

Migration

Commands

Value Constructors

Arithmetic

Comparison

Logic

Array

String

Math

Random

Type & Introspection

HashMap

Code Execution

Concurrency

Scheduler

Thread Safety

Error

Output

Time

Multiplayer

Compiler

Clone this wiki locally