Skip to content

API UO GetArrayLength en

Codex edited this page Oct 4, 2026 · 1 revision

UO.GetArrayLength

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

API · Basic

ClassicUO • Runtime API

Counts the direct slots of an Array for bounded iteration or safe indexing.

Exact syntax

UO.GetArrayLength(arg:Any) -> Any

Parameters

  • arg — Any BASIC value. Array returns its outer Length; String, number, Object and Unit return 0.

Returns

Integer >= 0. Empty Array and non-Array input both return 0, so the result alone cannot validate a type. This is a count, not Boolean or the last index.

Behavior

  • Local query: no server request, item movement or modification of the array. Examples use sample data, not a live inventory.
  • Checks the value kind and reads Array.Length; no traversal or summation. DIM values(2) allocates three slots, with indices 0..2, including uninitialized slots.
  • Nested elements are not counted recursively. Use Len for String length and the collection’s own Count for List/Dictionary objects. UO.GetArrayLength is the compatibility spelling of the same local query.

Internal functions: from call to result

Checks the value kind and reads Array.Length; no traversal or summation. DIM values(2) allocates three slots, with indices 0..2, including uninitialized slots.

1. GetArrayLength

Checks the value kind and reads Array.Length; no traversal or summation. DIM values(2) allocates three slots, with indices 0..2, including uninitialized slots.

Integer >= 0. Empty Array and non-Array input both return 0, so the result alone cannot validate a type. This is a count, not Boolean or the last index.

Project source: external/InjectionScript/src/InjectionScript/Runtime/InternalSubrutines.cs; function GetArrayLength.

Nested elements are not counted recursively. Use Len for String length and the collection’s own Count for List/Dictionary objects. UO.GetArrayLength is the compatibility spelling of the same local query.

Examples

Sum a bounded list of quantities

# Sum a bounded list of quantities
#
# Counts the direct slots of an Array for bounded iteration or safe indexing.
#
# Integer >= 0. Empty Array and non-Array input both return 0, so the result alone cannot
# validate a type. This is a count, not Boolean or the last index.

SUB Main()
    # DIM amounts(2) creates three entries. The loop visits indices 0..2 once and returns 150. These
    # sample quantities are summed by the loop, not by GetArrayLength.
    # Local query: no server request, item movement or modification of the array. Examples use
    # sample data, not a live inventory.

    Dim amounts(2)
    amounts[0] = 50
    amounts[1] = 75
    amounts[2] = 25
    Dim total = 0
    For index = 0 To UO.GetArrayLength(amounts) - 1
        total += amounts[index]
    Next
    Return total
END SUB

Parameter and execution notes:

  • DIM amounts(2) creates three entries. The loop visits indices 0..2 once and returns 150. These sample quantities are summed by the loop, not by GetArrayLength.
  • Local query: no server request, item movement or modification of the array. Examples use sample data, not a live inventory.

Count points and coordinate fields separately

# Count points and coordinate fields separately
#
# Counts the direct slots of an Array for bounded iteration or safe indexing.
#
# Integer >= 0. Empty Array and non-Array input both return 0, so the result alone cannot
# validate a type. This is a count, not Boolean or the last index.

SUB Main()
    # route has two point Arrays; each point has three coordinate slots. Main returns 2|3, not six.
    # The example does not move the character.
    # Local query: no server request, item movement or modification of the array. Examples use
    # sample data, not a live inventory.

    Dim first(2)
    first[0] = 100
    first[1] = 200
    first[2] = 0
    Dim second(2)
    second[0] = 101
    second[1] = 200
    second[2] = 0
    Dim route(1)
    route[0] = first
    route[1] = second
    Return CStr(UO.GetArrayLength(route)) & "|" & CStr(UO.GetArrayLength(route[0]))
END SUB

Parameter and execution notes:

  • route has two point Arrays; each point has three coordinate slots. Main returns 2|3, not six. The example does not move the character.
  • Local query: no server request, item movement or modification of the array. Examples use sample data, not a live inventory.

Guard the first index

# Guard the first index
#
# Counts the direct slots of an Array for bounded iteration or safe indexing.
#
# Integer >= 0. Empty Array and non-Array input both return 0, so the result alone cannot
# validate a type. This is a count, not Boolean or the last index.

SUB Main()
    # A String returns 0; Main returns no route before indexing. The same guard handles an empty
    # Array but cannot distinguish these two cases.
    # Local query: no server request, item movement or modification of the array. Examples use
    # sample data, not a live inventory.

    Dim route = "not an array"
    If UO.GetArrayLength(route) = 0 Then
        Return "no route"
    End If
    Return route[0]
END SUB

Parameter and execution notes:

  • A String returns 0; Main returns no route before indexing. The same guard handles an empty Array but cannot distinguish these two cases.
  • Local query: no server request, item movement or modification of the array. Examples use sample data, not a live inventory.

Clone this wiki locally