User Tools

Site Tools


4rpl:commands:getlistelement

This is an old revision of the document!



Lists Index

GetListElement

GetListElement (<-list I) ->element

Description

Returns the value at the specified index of a list. Lists are indexed from zero.

Note: If a list is stored in a variable, this can be abbreviated to <-list[<-index].

Examples

Split("1,2,3,4,5,6" ",") ->list
6 0 do
    Trace (<-list I GetListElement)  #functionally equivalent
    Trace (<-list[I])                #functionally equivalent
loop


<code 4rpl> # A 2-line code that gets a random element from a provided list. RandInt(0 GetListCount(<-units)) ->randIndex GetListElement(<-units <-randIndex) ->targetUnit </color>

<code 4rpl> # A function for selecting a random element from a list: 1 2 4 8 16 list ->list

<-list @selectRandomElement ->randElement

:selectRandomElement Dup Getlistcount 0 swap RandInt Getlistelement </color> ⇐ Index

4rpl/commands/getlistelement.1717915778.txt.gz · Last modified: 2025/02/14 14:56 (external edit)