Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I simplify this script?

Asked by 9 years ago

So I have an instructions GUI with lots of buttons and frames, and the script that makes the frames open and close is extremely inefficient. I have to manually add each frame every time a add a new button to the GUI, and its super time consuming. What I would like to know is if there is a function that can get all the children of a frame except one specific one. Is that possible?

01local BUTTON = script.Parent
02local TlFRAME = BUTTON.Parent.Parent
03local FRAME = TlFRAME.Arbalest
04local NAME = BUTTON.Text
05local ITEMNAME = FRAME.Itemname
06 
07local CRUDECLUB = TlFRAME.CrudeClub
08local HUNTINGCLUB =  TlFRAME.HuntingClub
09local FLINT = TlFRAME.Flint
10local CRUDEBUCKET = TlFRAME.CrudeBucket
11local COPPERAXE = TlFRAME.CopperAxe
12local COPPERPICKAXE = TlFRAME.CopperPickaxe
13local IRONAXE = TlFRAME.IronAxe
14local IRONPICKAXE = TlFRAME.IronPickaxe
15local CRUDEBOW = TlFRAME.CrudeBow
View all 73 lines...

3 answers

Log in to vote
0
Answered by 9 years ago

Sorry retread question I would still suggest using a for loop but with a conditional statement

1For I,v in pairs (Frame:Getchilrden()) do
2If v.Name ~=  -- item to avoid
3V.visible = false
4end
5end
0
That's actually a good answer. Since all the assets are held in TlFRAME and they are all being set to a certain property. M39a9am3R 3210 — 9y
Ad
Log in to vote
0
Answered by 9 years ago
01local BUTTON = script.Parent
02local ITFRAME = BUTTON.Parent.Parent
03local FRAME = ITFRAME.Hull
04local NAME = BUTTON.Text
05local ITEMNAME = FRAME.Itemname
06local SCROLLINGFRAME = ITFRAME.ScrollingFrame
07 
08FRAME.Visible = false
09 
10function on_button1_down()
11 
12    for I,v in pairs (FRAME:Getchilrden()) do
13if v.Name ~=  SCROLLINGFRAME-- item to avoid
14then v.Visible = false
15else I.Visible = true
View all 25 lines...

So would this work?

0
On line 15 I is only a number so it I'll error out, so just name it the thing, I is the number of the object in the table and v is the value raspyjessie 117 — 9y
0
OHHHHH thanks! Gwolflover 80 — 9y
0
oh wait now the error is "Getchildren is not a valid member of Frame Gwolflover 80 — 9y
0
You wrote "Getchilrden" instead of "GetChildren" 1waffle1 2908 — 9y
Log in to vote
0
Answered by
Wutras 294 Moderation Voter
9 years ago

That's a pretty simple problem and can easily be solved with a for _, fr in pairs(TlFrame:GetChildren()) do which will do the stuff inside of this and an end to anything inside of this table.

01local BUTTON = script.Parent
02local TlFRAME = BUTTON.Parent.Parent
03local FRAME = TlFRAME.Arbalest
04local NAME = BUTTON.Text
05local ITEMNAME = FRAME.Itemname
06 
07FRAME.Visible = false
08 
09function on_button1_down()
10    for _, fr in pairs(TlFrame:GetChildren()) do
11        if fr ~= FRAME then -- This will prevent the content of the FRAME variable from being changed.
12        fr.Visible = false
13        end
14    end
15    ITEMNAME.Text = NAME
16    FRAME.Visible = (not FRAME.Visible)
17end
18 
19BUTTON.MouseButton1Down:connect(on_button1_down)

If this doesn't help you with your problems or isn't what you needed, simply reply in a comment and I'll see what I can do.

0
ok I've adjusted it a bit and now it works except it makes all of the frames appear instead of just the one frame I want (called FRAME) Gwolflover 80 — 9y
0
local BUTTON = script.Parent local ITFRAME = BUTTON.Parent.Parent local FRAME = ITFRAME.SmallHandle local NAME = BUTTON.Text local ITEMNAME = FRAME.Itemname local SCROLLINGFRAME = ITFRAME.ScrollingFrame FRAME.Visible = false function on_button1_down() for _, fr in pairs(ITFRAME:GetChildren()) do if fr ~= SCROLLINGFRAME then -- This will prevent the content of the FRAME variable from Gwolflover 80 — 9y
0
Sorry its not easy to see here, I'll post the edited script on my other post ok? Gwolflover 80 — 9y

Answer this question