fairyoggy Posted January 13, 2020 Share Posted January 13, 2020 (edited) How to use random for letters? function asd() bb = {"A", "B", "C", "F", "G"} for _, i in ipairs( bb ) do z = end outputChatBox ( ""..z.."" ) end addCommandHandler ( "ss", asd ) How to write correctly "z" for random from "bb" Edited January 13, 2020 by slapztea Link to comment
Gw8 Posted January 13, 2020 Share Posted January 13, 2020 function asd() local bb = {"A", "B", "C", "F", "G"} local z = "" for _, i in ipairs( bb ) do z = i end outputChatBox(z) end addCommandHandler ( "ss", asd ) 1 Link to comment
fairyoggy Posted January 13, 2020 Author Share Posted January 13, 2020 Just now, Gw8 said: function asd() local bb = {"A", "B", "C", "F", "G"} local z = "" for _, i in ipairs( bb ) do z = i end outputChatBox(z) end addCommandHandler ( "ss", asd ) not working correctly, always output letter "G" but i need random from "bb" Example you type /ss and random output "B" next time maybe "C" and etc With your example, only the last letter is obtained "G" Link to comment
Gw8 Posted January 13, 2020 Share Posted January 13, 2020 Just now, slapztea said: not working correctly, always output letter "G" but i need random from "bb" Example you type /ss and random output "B" next time maybe "C" and etc With your example, only the last letter is obtained "G" function asd() local bb = {"A", "B", "C", "F", "G"} local z = bb[math.random(1,#bb)] outputChatBox(z) end addCommandHandler ( "ss", asd ) 1 Link to comment
fairyoggy Posted January 13, 2020 Author Share Posted January 13, 2020 1 minute ago, Gw8 said: function asd() local bb = {"A", "B", "C", "F", "G"} local z = bb[math.random(1,#bb)] outputChatBox(z) end addCommandHandler ( "ss", asd ) Nice, Thank you! Link to comment
fairyoggy Posted January 13, 2020 Author Share Posted January 13, 2020 One more question local test1 = 1 local test2 = 2 local test3 = 3 local ot = outputChatBox ( ""..ot.."" ) How to use random with this code? How do I make randomly choose one of the variables(test1 or test2 or test3) for "ot" ? Link to comment
Moderators Patrick Posted January 13, 2020 Moderators Share Posted January 13, 2020 44 minutes ago, slapztea said: One more question local test1 = 1 local test2 = 2 local test3 = 3 local ot = outputChatBox ( ""..ot.."" ) How to use random with this code? How do I make randomly choose one of the variables(test1 or test2 or test3) for "ot" ? test = { [1] = 1, [2] = 2, [3] = 3, } local ot = test[math.random(1, #test)] outputChatBox(ot) 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now