generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Alternative to table[math.random(1,#table)]?

Previous Thread :: Next Thread 
Tinfold is not online. Tinfold
Joined: 11 May 2010
Total Posts: 1435
06 Sep 2014 06:19 PM
Help. I'm making a guess what the guy is building game, and I use the code above to generate a word from a table, but it goes in the exact same order every time in online mode. Are there any alternatives to this method?
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
06 Sep 2014 08:15 PM
Try adding this line before that:
math.randomseed(tick())
Report Abuse
CrescentJade is not online. CrescentJade
Joined: 07 Jul 2010
Total Posts: 5494
06 Sep 2014 11:17 PM
generate a word???? or choose a word??

i made this:

---Making random word:

local array = {}
array.random = {}

metatable = {}


metatable.__call = function(t, ...)

local args = {...}
local tab = {}

if #args == 1 and pcall(function() args[1].hi = 1 end) then
args[1].hi = nil
args = {unpack(...)}
end

for i = 1,math.random(1,#args) do
table.insert(tab, args[math.random(1,#args)])
end

return unpack(tab)

end


setmetatable(array.random,metatable)


--Edit This Part

local r = {"d","a","m","o"} -- change this to table name and whats within the table

possible_words = {"mom","dad","mod","am","a","odd","mad"} -- add more

function check(tab)
wait()
for i,v in pairs(possible_words) do
if tab == v then
return true
else
check(tab)
end
end

k = nil

repeat k == array.random(r) until check(k)

print(k) -- this will print strings and numbers and stuff(parameters)
Report Abuse
CrescentJade is not online. CrescentJade
Joined: 07 Jul 2010
Total Posts: 5494
06 Sep 2014 11:19 PM
but that wont work
Report Abuse
CrescentJade is not online. CrescentJade
Joined: 07 Jul 2010
Total Posts: 5494
06 Sep 2014 11:32 PM
This would generate a word on the list:

local array = {}
array.random = {}

metatable = {}


metatable.__call = function(t, ...)

local args = {...}
local tab = {}

if #args == 1 and pcall(function() args[1].hi = 1 end) then
args[1].hi = nil
args = {unpack(...)}
end

for i = 1,math.random(1,#args) do
table.insert(tab, args[math.random(1,#args)])
end

local val = ""

for i,v in pairs(tab) do
val = val..v
end

return val

end


setmetatable(array.random,metatable)


--Edit This Part

local r = {"d","a","m","o"} -- change this to table name and whats within the table

possible_words = {"mom","dad","mod","am","add","odd","mad"} -- add more

function check(tab)
wait()
for i,v in pairs(possible_words) do
if tab == v then
bool = true
break
else
bool = false
end
end
return bool
end

k = array.random(r)

if not check(k) then

repeat k = array.random(r) until check(k)

end

print(k) -- this will print strings and numbers and stuff(parameters)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image