miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 08:19 PM |
for i,v in pairs(_G.myTable2) do table.insert(_G.myTable,v)--Fix THIS IF WRONG _G.myTable2[i] = nil end
Would everything from myTable2 remove? Or would I have to say
table.remove(_G.myTable2,i)
Pretty much, is saying _G.myTable2[i] = nil the same as using table.remove. |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2012 08:24 PM |
| I like using table.remove more. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 08:27 PM |
| Same here. But I'm asking, is this the same thing as using table.remove? |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 03 Mar 2012 08:29 PM |
no it wouldn't. table.remove takes the numerical INDEX
you can do
for i=#tab,1,-1 doo table.remove(tab,i); end
or better yet
tab={}; |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2012 08:31 PM |
"Pretty much, is saying _G.myTable2[i] = nil the same as using table.remove."
No. However, doing this:
t = {"hi", "potato", "qqq"} for i,v in next,t do t[i] = nil end print(#t)
will print 0, so it doesn't really matter when you're deleting all the values in the table.
@sduke: y u earlytoast |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 08:35 PM |
I'll just say this.
for i,v in pairs(_G.myTable2) do table.remove(_G.myTable2,i) end
Btw, what would this do?
for i,v in pairs(_G.myTable2) do _G.myTable2[i] = nil end
Would that just do nothing? |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 03 Mar 2012 08:42 PM |
@crazy Ironic since my keyboard is seriously glitched so I'm typing a character a minute. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 08:43 PM |
Can you just answer my question please? Will this remove it?
for i,v in pairs(_G.myTable2) do table.remove(_G.myTable2,i) end
Yes? |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2012 08:43 PM |
@SDuke: Then how did you type that entire sentence in only 10 minutes? hax :U
@miz: That would do the exact same thing as table.remove, as I posted above. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 08:46 PM |
@crazytomato4
How you posted using it or how I posted in the first post in the thread? Sorry, I'm in a rush.
Main point is yes it would work or no it wouldn't. |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 03 Mar 2012 08:47 PM |
@miz;
Meh depends. If all the indicies in your table are numeric sure that woild work but lets say your table looks like;
tab = {"aaa" = 44, "bbb" = 55, "ccc" = 66, ...}
It would break since table.remove only allows numeric indexes |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 08:48 PM |
If the table had something like this..
tab = {"IPlayfootball","TheFurryFox","Jimmyhen45"}
Would it break? Yes or no... In a rush :O |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 03 Mar 2012 08:50 PM |
@miz No
table.remove moves everything down that was behind that index so that it will stay in order. So if you follow the logic
local tab={'a','b','c','d'};
for i,v in pairs(tab) do table.remove(tab,i); end
1. starts [1]=a [2]=b [3]=c [4]=d
2. remove 1 [1]=b [2]=c [3]=d
3. remove 2 [1]=b [2]=d
4. remove 3 No 3, will error.
That is why when I did it I started from the back. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 08:53 PM |
So I should just say this?
for i,v in pairs(_G.myTable2) do table.insert(_G.myTable,v) _G.myTable2 = {} end
I should just say that to remove everything? Or should I do what crazytomato4 said using the next function? |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 03 Mar 2012 08:55 PM |
for i,v in pairs(_G.myTable2) do table.insert(_G.myTable,v) _G.myTable2[i] = nil end
|
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 08:56 PM |
@Smurf
That doesn't work...They said before in the earlier comments. |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2012 09:02 PM |
@miz: Yes, it does. I misspoke in my last comment, it wouldn't do the same as table.remove. the thing that smurf and I both posted would work, using an ascending loop and table.remove(t,i) wouldn't work. You could either do this:
for i,v in next,t do --? t[i] = nil end
this:
for i,v in next,t do --? end t = {}
or this:
for i = #t,1,-1 do --? table.remove(t,i) end
(the first two loops can be constructed however you want, all the "--?"s are basically 'stuff goes here')
There may be other ways, but those three should work with any table made up of numeric indices. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 09:07 PM |
It didn't work because the gui's text wasn't the same(Different script.)
I think I'ma use it twice. I think I'm gonna say _G.myTable2 = {}
One question: for i,v in next,t do --? end t = {}
Did you have to put t = {} outside the scope or could it go right after the --? and before the end? |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2012 09:08 PM |
If you were to put `t = {}` inside the loop, it would empty the table after the first iteration of the loop. Pretty sure that isn't what you want.
Lrn2flowcontrol |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 09:10 PM |
Thanks crazy.
One more thing. Just to make sure this is the reason the game doesn't work.
script.Parent.Parent.Parent.Parent.MainGui["1Gui"].One.Changed:connect(function(change) if script.Parent.Parent.Parent.Parent.MainGui["1Gui"].One.Visible == true then script.Parent.Parent.Parent.Parent.MainGui["1Gui"].One.Text = _G.myTable2[1] end end)
This will run every time One is visibe, right? Just checkin so this isn't why it breaks. |
|
|
| Report Abuse |
|
|
|
| 03 Mar 2012 09:13 PM |
1. variables plz
2. yep, although it will also run whenever anything else changes and visible is still true, for example, if you change its position or text while it is visible, it will run again.
local one = script.Parent.Parent.Parent.Parent.MainGui["1Gui"].One one.Changed:connect(function(p) if p == "Visible" and one.Visible then one.Text = _G.myTable2[1] end end) |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 09:16 PM |
| Ok, that's fine. Thanks crazytomato4 :) |
|
|
| Report Abuse |
|
|
smurf279
|
  |
| Joined: 15 Mar 2010 |
| Total Posts: 6871 |
|
|
| 03 Mar 2012 09:21 PM |
Actually know that I think about it: ----[code] for i,v in pairs(_G.myTable2) do table.insert(_G.myTable,v) _G.myTable2 = {} end ----[code]
Would still work. This: ----[code] for i,v in pairs(_G.myTable2) do table.insert(_G.myTable,v) end _G.myTable2 = {} ----[code]
Would still be more effecient but unlike Python or some other languages, Lua evaluates the expression inside of the for loop before the loop begins, so it safe to edit the table during the loop. |
|
|
| Report Abuse |
|
|
miz656
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 15336 |
|
|
| 03 Mar 2012 09:27 PM |
I did this
for i,v in pairs(_G.myTable2) do table.insert(_G.myTable,v) _G.myTable2[i] = nil end _G.myTable2 = {}
Just in case the 3rd line doesn't work.
|
|
|
| Report Abuse |
|
|