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 8 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?

local BUTTON = script.Parent
local TlFRAME = BUTTON.Parent.Parent
local FRAME = TlFRAME.Arbalest
local NAME = BUTTON.Text
local ITEMNAME = FRAME.Itemname

local CRUDECLUB = TlFRAME.CrudeClub
local HUNTINGCLUB =  TlFRAME.HuntingClub
local FLINT = TlFRAME.Flint
local CRUDEBUCKET = TlFRAME.CrudeBucket
local COPPERAXE = TlFRAME.CopperAxe
local COPPERPICKAXE = TlFRAME.CopperPickaxe
local IRONAXE = TlFRAME.IronAxe
local IRONPICKAXE = TlFRAME.IronPickaxe 
local CRUDEBOW = TlFRAME.CrudeBow
local CRUDEFISHINGROD = TlFRAME.CrudeFishingRod
local LONGBOW = TlFRAME.Longbow
local SHORTBOW = TlFRAME.Shortbow
local HUNTINGBOW = TlFRAME.HuntingBow 
local FISHINGROD = TlFRAME.FishingRod
local CROSSBOW = TlFRAME.Crossbow 
local ARBALEST = TlFRAME.Arbalest 
local STEELAXE = TlFRAME.SteelAxe 
local STEELPICKAXE = TlFRAME.SteelPickaxe 
local BUCKET = TlFRAME.Bucket 
local CRAFTINGKNIFE = TlFRAME.CraftingKnife 
local SKINNINGKNIFE = TlFRAME.SkinningKnife 
local LUMBERSAW = TlFRAME.Lumbersaw 
local SLEDGEHAMMER = TlFRAME.SledgeHammer 
local MASONRYHAMMER = TlFRAME.MasonryHammer 
local BLUNDERBUSS = TlFRAME.Blunderbuss 
local FLINTSTEEL = TlFRAME.FlintSteel 
local DYE = TlFRAME.Dye 

FRAME.Visible = false

function on_button1_down()

    CRUDECLUB.Visible = false
    HUNTINGCLUB.Visible = false
    FLINT.Visible = false
    CRUDEBUCKET.Visible = false
    COPPERAXE.Visible = false
    COPPERPICKAXE.Visible = false
    IRONAXE.Visible = false
    IRONPICKAXE.Visible = false
    CRUDEBOW.Visible = false
    CRUDEFISHINGROD.Visible = false
    LONGBOW.Visible = false
    SHORTBOW.Visible = false
    HUNTINGBOW.Visible = false
    FISHINGROD.Visible = false
    CROSSBOW.Visible = false
    --ARBALEST.Visible = false
    STEELAXE.Visible = false
    STEELPICKAXE.Visible = false
    BUCKET.Visible = false
    CRAFTINGKNIFE.Visible = false
    SKINNINGKNIFE.Visible = false
    LUMBERSAW.Visible = false
    SLEDGEHAMMER.Visible = false
    MASONRYHAMMER.Visible = false
    BLUNDERBUSS.Visible = false
    FLINTSTEEL.Visible = false
    DYE.Visible = false

    ITEMNAME.Text = NAME

    FRAME.Visible = (not FRAME.Visible)

    end

BUTTON.MouseButton1Down:connect(on_button1_down)

3 answers

Log in to vote
0
Answered by 8 years ago

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

For I,v in pairs (Frame:Getchilrden()) do
If v.Name ~=  -- item to avoid
V.visible = false
end
end
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 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
local BUTTON = script.Parent
local ITFRAME = BUTTON.Parent.Parent
local FRAME = ITFRAME.Hull
local NAME = BUTTON.Text
local ITEMNAME = FRAME.Itemname
local SCROLLINGFRAME = ITFRAME.ScrollingFrame

FRAME.Visible = false

function on_button1_down()

    for I,v in pairs (FRAME:Getchilrden()) do
if v.Name ~=  SCROLLINGFRAME-- item to avoid
then v.Visible = false
else I.Visible = true
end


    ITEMNAME.Text = NAME

    FRAME.Visible = (not FRAME.Visible)

    end
    end
BUTTON.MouseButton1Down:connect(on_button1_down)

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 — 8y
0
OHHHHH thanks! Gwolflover 80 — 8y
0
oh wait now the error is "Getchildren is not a valid member of Frame Gwolflover 80 — 8y
0
You wrote "Getchilrden" instead of "GetChildren" 1waffle1 2908 — 8y
Log in to vote
0
Answered by
Wutras 294 Moderation Voter
8 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.

local BUTTON = script.Parent
local TlFRAME = BUTTON.Parent.Parent
local FRAME = TlFRAME.Arbalest
local NAME = BUTTON.Text
local ITEMNAME = FRAME.Itemname

FRAME.Visible = false

function on_button1_down()
    for _, fr in pairs(TlFrame:GetChildren()) do
        if fr ~= FRAME then -- This will prevent the content of the FRAME variable from being changed.
        fr.Visible = false
        end
    end
    ITEMNAME.Text = NAME
    FRAME.Visible = (not FRAME.Visible)
end

BUTTON.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 — 8y
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 — 8y
0
Sorry its not easy to see here, I'll post the edited script on my other post ok? Gwolflover 80 — 8y

Answer this question