Jump to content

random for letter


fairyoggy

Recommended Posts

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
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 )

 

  • Like 1
Link to comment
  • Moderators
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)

 

  • Like 1
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...