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 » Scripters
Home Search
 

Re: table.remove()

Previous Thread :: Next Thread 
Blacksun1998 is not online. Blacksun1998
Joined: 06 Aug 2013
Total Posts: 59
06 Jul 2015 04:31 AM
t = {1,2,3,4,5}

for i,v in pairs (t) do
table.remove(t,3)
end

print(table.concat(t," "))

console output: 1 2

is it ment to do this? i want so it removes only the item at index 3 and just sorts the rest or just leaves an empty space. is this possible?
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
06 Jul 2015 04:34 AM
You put it in a loop

t = {1,2,3,4,5}

for i,v in pairs (t) do
table.remove(t,3)
end

after iteration 1
1, 2, 4, 5
after iteration 2
1, 2, 5
after iteration 3
1, 2

t = {1,2,3,4,5}
table.remove(t,3)

will do what you intended
Report Abuse
Blacksun1998 is not online. Blacksun1998
Joined: 06 Aug 2013
Total Posts: 59
06 Jul 2015 04:36 AM
nevermind this was such a stupid fault... just ignore it! thanks :D
Report Abuse
Blacksun1998 is not online. Blacksun1998
Joined: 06 Aug 2013
Total Posts: 59
06 Jul 2015 04:58 AM
wait no

the thing is you are right
but i think lua glitches out
i am working on a pathfinding code

and i have a list with blocks. they are Nodes. just parts somewhere in the game

so what i did is i putted them in a list called unvisited
every time the code visits a new node he has to remove it from the unvisited list and put it in the visited list

table.insert(visited,pos2,current)
for i,v in pairs(unvisited) do
if (current.Name == v.Name) then
table.remove(unvisited,i)
print(i)
print(v.Name)
end
end

this is the code, but every time he reaches the number he removes EVERYTHING from the list above his number

i have 21 nodes, and when he reaches the current node, which is node 16 he removes node16, 17, 18, 19, 20, 21

roblox should sort it out
like:


ROBLOX Forum » Game Creation and Development » Scripters

Home Search MyForums

Reply to Post
Original Post
table.remove()
Posted by Blacksun1998 on 07-06-2015 04:31 AM

t = {1,2,3,4,5}

table.remove(t,3)

this would give me: {1,2,4,5} it places all the other item 1 down and sorts the list

but in my program it does not place them 1 down it just removes them. is this a glich? i am looking for hours now and i dont get this why he does this
Report Abuse
Blacksun1998 is not online. Blacksun1998
Joined: 06 Aug 2013
Total Posts: 59
06 Jul 2015 05:26 AM
if you dont get what i mean
here i use a breakpoint

Before executing the command table.remove: http://puu.sh/iOVo9/32f5d5f6c9.png
After executing the command table.remove: http://puu.sh/iOVpY/1bd3f20c7a.png

instead of removing only 1 item it removes everything... which it should not...
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
06 Jul 2015 05:36 AM
It's kind of hard to diagnose so abstractly but I have a feeling that breaking the loop after the if statement has executed would be helpful.

for i,v in pairs(unvisited) do
if (current.Name == v.Name) then
table.remove(unvisited,i)
print(i)
print(v.Name)
break
end
end

I assume you know there is a PathFindingService but you are choosing to make your own algorithm anyway, correct?
Report Abuse
Blacksun1998 is not online. Blacksun1998
Joined: 06 Aug 2013
Total Posts: 59
06 Jul 2015 06:05 AM
i will try that out soon
now i did unvisited[i] = nil

that seems to work
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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