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: Multiple event connections

Previous Thread :: Next Thread 
dansk is not online. dansk
Joined: 24 Dec 2008
Total Posts: 548
30 Jul 2014 01:08 AM
Heres the template:

local allTabs = {}

function Click()
if allTabs = script.Parent.Button1 then
end
if allTabs = script.Parent.Button2 then
end
end

allTabs.MouseButton1Down:connect(Click)

The scenario: I have this script in a local script inside a frame along with 5 buttons in it. Instead of using multiple events saying: script.Parent.().MouseButton1Down:connect() (I would need to put 5 of these for 5 buttons), is there an easier way to
combine all of the buttons using a table like allTabs = {script.Parent.Button1, script.Parent.Button2} Then just put the allTabs table in the MouseButton1Down event? Also, if this is possible, how do I retrieve which button was pressed? Idk something like if allTabs = 1 then???
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
30 Jul 2014 01:19 AM

Any questions?

-----------------------
local Frame = script.Parent.Parent -- depends on the script

-- @Param obj = the object to use
-- Uses a button based on the object
local useButton = function(obj)
-- use the button based of name
end

-- @Param v = the object to be added a mouse down event to
-- Assigns an event to an object
local assignEvent = function(v)
v.MouseButton1Down:connect(function()
useButton(v)
end
end

-- Iterates thru the frame or wherever to find anything but scripts
-- adds an event to the objects.
for _, v in pairs(Frame:GetChildren())do
if(not v:IsA("Script")) or (not v:IsA("LocalScript"))then
assignEvent(v)
end
end
Report Abuse
dansk is not online. dansk
Joined: 24 Dec 2008
Total Posts: 548
30 Jul 2014 01:36 AM
So the function useButton(obj) is the function that I use to create whatever im going to do in it? And the obj parameter returns the Button right? so I could do: if obj.Name == "Button1" then...? Is that right? Also I have a frame with buttons in it and a boolvalue inside of all the buttons in the first layer of the frame. Will that pick up on it? If so, could I use the normal for function with in pairs to just return the first layer of buttons?
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
30 Jul 2014 01:45 AM
Tab = {ButtonPathHere,ButtonPathHere,ButtonPathHere}
for i,v in pairs(Tab) do
v.MouseButton1Down:connect(function()
if v == Tab[1] then
--More Code here
end
end)
end
Report Abuse
dansk is not online. dansk
Joined: 24 Dec 2008
Total Posts: 548
30 Jul 2014 01:50 AM
Though will in pairs skiip over the frame with buttons in my button or look through that as well?
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
30 Jul 2014 02:07 AM
local table = {"a", "b", "c"}

for i, v in pairs(table)do
print(i, v)
end

>> 1 a
>> 2 b
>> 3 c

---------

for i, v in pairs(game.Workspace:GetChildren())do
print(i, v)
end

>> 1 Terrain
>> 2 Camera
>> 3 cody123454321
>> 4 BasePlate
>> 5 Script

Report Abuse
dansk is not online. dansk
Joined: 24 Dec 2008
Total Posts: 548
30 Jul 2014 02:43 AM
Guys im just looking for yes or no
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
30 Jul 2014 02:48 AM
You'll have to look through the frame inside the button.
Report Abuse
dansk is not online. dansk
Joined: 24 Dec 2008
Total Posts: 548
30 Jul 2014 02:51 AM
This is my question: Does for i,v in pairs look through a frame with buttons in it inside of a button or will it skip over it? Its yes or no.
Report Abuse
AnonyAnonymous is not online. AnonyAnonymous
Joined: 23 Jun 2013
Total Posts: 6332
30 Jul 2014 02:54 AM
No, it's only going to iterate through the children of the frame.

If you're referring to accessing children of the button then

Something such as,
v.ChildNameHere
assuming "v" is the button which is the child of the frame.

You could also just loop through "v".
Report Abuse
dansk is not online. dansk
Joined: 24 Dec 2008
Total Posts: 548
30 Jul 2014 03:31 AM
Ok thank you thats all I need
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