Skip to content

API ASC en

Codex edited this page Oct 3, 2026 · 1 revision

ASC

API · BASIC

Русский · English · Українська · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

ASC · Chr · len · StrComp

ClassicUO • Runtime API

Reads a character code or parses a whole-number setting. The number of arguments selects two different operations.

Exact syntax

ASC(text:String, defaultValue:Integer) -> Integer
ASC(value:String) -> Integer

Parameters

  • value / text — String. With one argument, read its first UTF-16 code unit. With two arguments, parse the complete decimal or 0x hexadecimal text, allowing an outer sign and whitespace.
  • defaultValue — Integer fallback, required only by the two-argument form. Returned when parsing fails; it is not a default character code.

Returns

Integer. ASC(text): 0..65535, or 0 for empty text. ASC(text, fallback): a parsed Int32 or fallback. Decimal overflow fails; unsigned hex through 0xFFFFFFFF is interpreted as the signed 32-bit bit pattern, so 0xFFFFFFFF returns -1. Fractions and suffixes are rejected.

Behavior

  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.
  • ASC is not a numeric success flag. The character form reads Unicode, not a locale-dependent ANSI byte. For an emoji it returns the leading surrogate, not the full Unicode scalar. A fallback can equal a valid result; choose one outside the allowed application range.

Internal functions: from call to result

Overload selection checks arity. One argument reads text[0] or zero; two call TryStr2Int and choose the parsed value or fallback. Nothing is looked up in the game world.

1. BasicAsc / Asc / NumberConversions.TryStr2Int

Overload selection checks arity. One argument reads text[0] or zero; two call TryStr2Int and choose the parsed value or fallback. Nothing is looked up in the game world.

Integer. ASC(text): 0..65535, or 0 for empty text. ASC(text, fallback): a parsed Int32 or fallback. Decimal overflow fails; unsigned hex through 0xFFFFFFFF is interpreted as the signed 32-bit bit pattern, so 0xFFFFFFFF returns -1. Fractions and suffixes are rejected.

Project source: external/InjectionScript/src/InjectionScript/Runtime/InjectionApi.cs; function BasicAsc / Asc / NumberConversions.TryStr2Int.

ASC is not a numeric success flag. The character form reads Unicode, not a locale-dependent ANSI byte. For an emoji it returns the leading surrogate, not the full Unicode scalar. A fallback can equal a valid result; choose one outside the allowed application range.

Examples

Read one digit

# Read one digit
#
# Reads a character code or parses a whole-number setting. The number of arguments selects two
# different operations.
#
# Integer. ASC(text): 0..65535, or 0 for empty text. ASC(text, fallback): a parsed Int32 or
# fallback. Decimal overflow fails; unsigned hex through 0xFFFFFFFF is interpreted as the signed
# 32-bit bit pattern, so 0xFFFFFFFF returns -1. Fractions and suffixes are rejected.

SUB Main()
    # ASC("7") = 55. The 48..57 test checks ASCII digits before subtracting 48; Main returns 7.
    # Runs locally. Examples process sample data and return a value; they do not send chat, stop a
    # script, move items or contact the server.

    Dim code = ASC("7")
    If code >= 48 AndAlso code <= 57 Then
        Return code - 48
    End If
    Return -1
END SUB

Parameter and execution notes:

  • ASC("7") = 55. The 48..57 test checks ASCII digits before subtracting 48; Main returns 7.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Read an item graphic setting

# Read an item graphic setting
#
# Reads a character code or parses a whole-number setting. The number of arguments selects two
# different operations.
#
# Integer. ASC(text): 0..65535, or 0 for empty text. ASC(text, fallback): a parsed Int32 or
# fallback. Decimal overflow fails; unsigned hex through 0xFFFFFFFF is interpreted as the signed
# 32-bit bit pattern, so 0xFFFFFFFF returns -1. Fractions and suffixes are rejected.

SUB Main()
    # "0x0EED" is parsed to 3821. The -1 fallback rejects this example’s invalid setting; no item is
    # selected or moved.
    # Runs locally. Examples process sample data and return a value; they do not send chat, stop a
    # script, move items or contact the server.

    Dim graphicText = "0x0EED"
    Dim graphic = ASC(graphicText, -1)
    If graphic = -1 Then
        Return "invalid graphic"
    End If
    Return graphic
END SUB

Parameter and execution notes:

  • "0x0EED" is parsed to 3821. The -1 fallback rejects this example’s invalid setting; no item is selected or moved.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Validate a quantity

# Validate a quantity
#
# Reads a character code or parses a whole-number setting. The number of arguments selects two
# different operations.
#
# Integer. ASC(text): 0..65535, or 0 for empty text. ASC(text, fallback): a parsed Int32 or
# fallback. Decimal overflow fails; unsigned hex through 0xFFFFFFFF is interpreted as the signed
# 32-bit bit pattern, so 0xFFFFFFFF returns -1. Fractions and suffixes are rejected.

SUB Main()
    # ReadQuantity parses the complete text and requires 1..100. "invalid" returns -1; "50" would
    # return 50. No stack is modified.
    # Runs locally. Examples process sample data and return a value; they do not send chat, stop a
    # script, move items or contact the server.

    Return ReadQuantity("invalid", 1, 100)
END SUB

Function ReadQuantity(text, minimum, maximum)
    Dim quantity = ASC(text, -1)
    If quantity < minimum OrElse quantity > maximum Then
        Return -1
    End If
    Return quantity
End Function

Parameter and execution notes:

  • ReadQuantity parses the complete text and requires 1..100. "invalid" returns -1; "50" would return 50. No stack is modified.
  • Runs locally. Examples process sample data and return a value; they do not send chat, stop a script, move items or contact the server.

Clone this wiki locally