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: I have a problem.

Previous Thread :: Next Thread 
Trioxide is not online. 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 is not online. 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 is not online. 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 is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
04 May 2013 08:12 AM
Yes, got it working with coroutines.
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