|
| 15 Feb 2014 01:34 PM |
I have these three functions here. "map" is the map where there are eight vector3 values stored. What this script does is put those values into a table, then randomly select five of them without the same one being picked twice.
However, when I do print(value) I do get the same value twice. Try reading it from the bottom then make your way up.
function choosevalue() value = math.random(1, #locations) number = locations[value] table.remove(locations, value) --This is supposed to remove the vector 3 so it can't be picked again but that doesn't work. return number.Value end function tableadd(map) for i,v in pairs (map.Locations:GetChildren()) do table.insert(locations, v) end end
function hideitems(map) tableadd(map) --This adds the values to a table. for i = 1, 5 do value = choosevalue() --Selects a value from the table. table.insert(vector3values, value) --Adds it to a new table print(value) end end |
|
|
| Report Abuse |
|
|
L0cky2013
|
  |
| Joined: 30 Jul 2012 |
| Total Posts: 1446 |
|
|
| 15 Feb 2014 01:38 PM |
for i=1, #locations do if locations[i] == value then table.remove(locations, i) end end |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2014 01:41 PM |
Sorry, where does this go?
Thanks! |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2014 03:18 PM |
Is it like this?
function choosevalue() value = math.random(1, #locations) number = locations[value] for i=1, #locations do if locations[i] == value then table.remove(locations, i) end end return number.Value end
This isn't working either. The same one comes up more than once.:( |
|
|
| Report Abuse |
|
|
|
| 15 Feb 2014 03:20 PM |
remove() doesn't use the value, it uses the index.
ReoveByValue(Table, Value) for Index, value in pairs(Table) do if Value == value then table.remove(Table, Index) end end end |
|
|
| Report Abuse |
|
|
| |
|
|
| 16 Feb 2014 03:16 AM |
| Any where in the script, also, I forgot to put 'function' before RemoveByValue |
|
|
| Report Abuse |
|
|
|
| 16 Feb 2014 06:42 AM |
| Okay thanks! Yeah that did muddle me up a bit...:3 Thank yooooou |
|
|
| Report Abuse |
|
|