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: table.remove() and loops.

Previous Thread :: Next Thread 
Sam3812 is not online. Sam3812
Joined: 23 Nov 2007
Total Posts: 1703
09 Jul 2012 06:20 PM
Okay, so I'm having some trouble here.

As most of us know, using table.remove() will cause all the table entries to shift, so when used in an incremental loop, i will change.

I have this script here.

for i, v in pairs(table) do
if v.X is < limitMin or v.X > limitMax then
table.remove(table, i)
elseif v.Z is < limitMin or v.Z > limitMax then
table.remove(table, i)
end
end

Now it works until v happens to land on a corner, in which case there will be two properties that exceed the limit. It will only then remove one of the properties and continue on the script, which is a huge problem.

How can I make it reliably remove both?

Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
09 Jul 2012 06:33 PM
Numeric for?


for i = 1, #tab do
local v = tab[i]
if v.X is < limitMin or v.X > limitMax then
table.remove(tab, i)
elseif v.Z is < limitMin or v.Z > limitMax then
table.remove(tab, i)
end
end
Report Abuse
Sam3812 is not online. Sam3812
Joined: 23 Nov 2007
Total Posts: 1703
09 Jul 2012 06:34 PM
So say I had this.

table = {
Vector3.new(limitMin-1, 0, limitMin-1),
Vector3.new(limitMin-1, 0, limitMin-1)
}

table[1].X = limitMin - 1 and table[1].Z = limitMin - 1

take into account the forementioned loop and table[1] will be removed
then table[2] wouldn't be table[2], it would be table [1], as table[1] has already been checked, it won't be check again, so even though table[2] was outside the extents of the limit, because it's not going to be checked, it's going to remain.

I need a way to remove this issue.

A work around, or a fix would be great.

Report Abuse
Sam3812 is not online. Sam3812
Joined: 23 Nov 2007
Total Posts: 1703
09 Jul 2012 06:36 PM
The same problem occurs with an incremental loop, as that was the type of loop I was originally using.

Hopefully the explanation of why that I posted above will help us reach a solution.
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
09 Jul 2012 06:41 PM
ohh then don't use table.remove. just do table[index] = nil
Report Abuse
Sam3812 is not online. Sam3812
Joined: 23 Nov 2007
Total Posts: 1703
09 Jul 2012 06:47 PM
I can't as I'm using #table for a later part of the script, and it's necessary that I don't have any nil values in it.
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
09 Jul 2012 06:51 PM
function getNum(tab)
local count = 0
for i, v in next, tab do
count = count+1
end
return count
end

i had the same problem with a script I was making before lol
or maybe table[index] = "nil"
and then remove all the "nil" values after that portion of the code?
Report Abuse
Sam3812 is not online. Sam3812
Joined: 23 Nov 2007
Total Posts: 1703
09 Jul 2012 06:54 PM
Okay, both sound like they should work.

Thanks, I'll go give them a shot.
Report Abuse
Sam3812 is not online. Sam3812
Joined: 23 Nov 2007
Total Posts: 1703
09 Jul 2012 06:58 PM
table[i] = nil

Output:
"Can't modify this library"

What even is?
Report Abuse
Sam3812 is not online. Sam3812
Joined: 23 Nov 2007
Total Posts: 1703
09 Jul 2012 06:59 PM
Nevermind, I was being silly :).
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
09 Jul 2012 07:02 PM
its cause you're using a variable named table which is the same name as the library table
IE table.remove, table.inset, table.pack, ect...

anyways just change the variable name for your table.
Report Abuse
smurf279 is not online. smurf279
Joined: 15 Mar 2010
Total Posts: 6871
09 Jul 2012 07:03 PM
^^^late post^^^
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