random - Lua function selector -


i have 3 functions. when user presses 'e' key want select 1 of functions (at random), feel has math.random can't figure out.

you don't use math.random select function; use pick random number, can use index function need table (as 1 example):

local list = { function() print(1) end, function() print(2) end, function() print(3) end } math.randomseed(os.time()) -- don't forget seed or same sequence = 1, 10 list[math.random(#list)]() end 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -