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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: table.remove() help?

Previous Thread :: Next Thread 
rudolph101 is not online. rudolph101
Joined: 15 Jan 2009
Total Posts: 11873
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 is not online. 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
rudolph101 is not online. rudolph101
Joined: 15 Jan 2009
Total Posts: 11873
15 Feb 2014 01:41 PM
Sorry, where does this go?

Thanks!
Report Abuse
rudolph101 is not online. rudolph101
Joined: 15 Jan 2009
Total Posts: 11873
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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
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
rudolph101 is not online. rudolph101
Joined: 15 Jan 2009
Total Posts: 11873
15 Feb 2014 05:21 PM
Where does that go?:3
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
16 Feb 2014 03:16 AM
Any where in the script, also, I forgot to put 'function' before RemoveByValue
Report Abuse
rudolph101 is not online. rudolph101
Joined: 15 Jan 2009
Total Posts: 11873
16 Feb 2014 06:42 AM
Okay thanks! Yeah that did muddle me up a bit...:3 Thank yooooou
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