Select
Available since: Gideros 2011.6
Class: (global)
Description
Returns items in a list. <syntaxhighlight lang="lua"> (any) = select(index,...) </source>
If index is a number, returns all items in the list from that number onwards. Otherwise index must be the string "#", in which case it returns the number of items in the list.
Parameters
index: (number or "#") number, all items in the list from that number onwards. "#", number of items in the list
...: (any) the list to process
Examples
<syntaxhighlight lang="lua"> function f(...) print (select ("#", ...)) --> 4 print (select (2, ...)) --> r 32 z end
f("b", "r", 32, "z") </source>
Select a random weapon <syntaxhighlight lang="lua"> local random = math.random
function choose(...) local index = random(select("#", ...)) local result = select(index, ...) -- store only value at index (omitting the other values) -- local result = select(random(select("#",...)), ...) -- same as above but in one line return result end
local weapon = choose("pistol", "auto", "falcon", "rpg", "test") print("random weapon: "..weapon) -- eg. "random weapon: falcon" </source>