Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
|
| 04 May 2013 07:35 AM |
Let's say I have this script: buttons = {TextButton1,TextButton2,TextButton3}
for _,v in pairs(buttons) do v.MouseButton1Down:connect(function() print(v.Name) end end
And I do this at some part: table.insert(buttons,TextButton4)
If I click TextButton4, the script doesn't print its name.
__How do I 'update' the table/loop thingie without resetting the script?__ |
|
|
| Report Abuse |
|
|
jobro13
|
  |
| Joined: 05 Aug 2009 |
| Total Posts: 2865 |
|
|
| 04 May 2013 07:44 AM |
buttons = {TextButton1,TextButton2,TextButton3}
for _,v in pairs(buttons) do v.MouseButton1Down:connect(function() print(v.Name) end end
local mt = {} mt.__newindex = function(tab, ind, val) if type(val) == "userdata" and val:IsA("TextButton") then v.MouseButton1Down:connect(function() print(v.name) end) end end
setmetatable(buttons, mt)
USE
buttons[#buttons+1] = val |
|
|
| Report Abuse |
|
|
Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
|
| 04 May 2013 07:47 AM |
| Uhm, I guess I could try to use coroutines. Metatables are a bit too hard for me. :L |
|
|
| Report Abuse |
|
|
Trioxide
|
  |
| Joined: 29 Mar 2011 |
| Total Posts: 32902 |
|
|
| 04 May 2013 08:12 AM |
| Yes, got it working with coroutines. |
|
|
| Report Abuse |
|
|