User Tools

Site Tools


4rpl:commands:getlistelement

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
4rpl:commands:getlistelement [2021/01/08 16:01] – external edit 127.0.0.14rpl:commands:getlistelement [2025/02/14 14:57] (current) – external edit 127.0.0.1
Line 1: Line 1:
-~~NOTOC~~+ \\ 
 +<=[[4rpl:start#lists| Lists]]~~NOTOC~~
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
 +<WRAP tabs> 
 +  * [[4rpl:commands:getlistelement|Get]] 
 +  * [[4rpl:commands:setlistelement|Set]] 
 +</WRAP>
 ====== GetListElement ====== ====== GetListElement ======
 GetListElement (<-list I) ->element GetListElement (<-list I) ->element
Line 17: Line 21:
     Trace (<-list[I])                #functionally equivalent     Trace (<-list[I])                #functionally equivalent
 loop loop
 +</code>
 +
 +<code 4rpl>
 +# A 2-line code that gets a random element from a provided list.
 +RandInt(0 GetListCount(<-units)) ->randIndex
 +GetListElement(<-units <-randIndex) ->targetUnit
 +</code>
 +
 +<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 
 </code> </code>
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
  
4rpl/commands/getlistelement.1610121708.txt.gz · Last modified: 2025/02/14 14:56 (external edit)