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 » Scripting Helpers
Home Search
 

Re: How to mix around a table

Previous Thread :: Next Thread 
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
30 Mar 2014 02:11 AM
How can I do this:
mytable = {1,2,3,4,5}
and then mix it around so it can POSSIBLY go into a random order like this:
mytable = {3,1,5,4,2}
Report Abuse
MrChubbs is not online. MrChubbs
Joined: 14 Oct 2010
Total Posts: 4969
30 Mar 2014 02:15 AM
local tab = {} --Insert ST00f
local newtable = {}
math.randomseed(tick())
while #tab > 0 do
index = math.random(1, #tab)
newtable[#newtable+1] = tab[index]
table.remove(tab, index)
end
tab = newtable
Report Abuse
iYoshiFox is not online. iYoshiFox
Joined: 14 Apr 2012
Total Posts: 1058
30 Mar 2014 02:16 AM
local Table = {1, 2, 3, 4, 5}

function Mix(tbl) --tbl = the table ur mixing
local mixed = {}
local g = tbl
repeat
wait()
local rand = math.random(1, #g)
table.insert(mixed, g[rand])
table.remove(g, g[rand])
until #mixed == #tbl
end
Report Abuse
iYoshiFox is not online. iYoshiFox
Joined: 14 Apr 2012
Total Posts: 1058
30 Mar 2014 02:17 AM
MrChubbs, yours would look like this;

newtable = {
[1] = 1
[2] = 2 -Ect
}
Report Abuse
iYoshiFox is not online. iYoshiFox
Joined: 14 Apr 2012
Total Posts: 1058
30 Mar 2014 02:19 AM
Put this at the end of mu function under

'until #mixed == #tbl'
return mixed





then, if you did this

for _, v in pairs(Mix(Table)) do --You already have the contents.
end
Report Abuse
MrChubbs is not online. MrChubbs
Joined: 14 Oct 2010
Total Posts: 4969
30 Mar 2014 02:21 AM
Mine randomizes tables correctly, I just checked it.
Report Abuse
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
30 Mar 2014 02:33 AM
local Table = {1, 2, 3, 4, 5}
print(Table[3])
function Mix(tbl) --tbl = the table ur mixing
mixed = {}
local g = tbl
repeat
wait()
local rand = math.random(1, #g)
table.insert(mixed, g[rand])
table.remove(g, g[rand])
until #mixed == #tbl
return mixed
end
print(mixed[3])

--With this i am getting error of mixed is a nil value?
Report Abuse
iYoshiFox is not online. iYoshiFox
Joined: 14 Apr 2012
Total Posts: 1058
30 Mar 2014 02:34 AM
Do this:

print(Mix(Table)[3])
Report Abuse
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
30 Mar 2014 02:35 AM
Oh right, forgot it was a function, will test.
Report Abuse
iYoshiFox is not online. iYoshiFox
Joined: 14 Apr 2012
Total Posts: 1058
30 Mar 2014 02:36 AM
Tell me if it worked.. I did do it off the top of my head..
Report Abuse
KiwiTronik is not online. KiwiTronik
Joined: 18 Feb 2010
Total Posts: 3221
30 Mar 2014 02:37 AM
Hmm, still getting errors.
I'm going to go with MrChubbs script

Thanks for the help anyways!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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