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
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 06 Sep 2014 08:15 PM |
Try adding this line before that: math.randomseed(tick()) |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|