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

Help me prepare something like a "switch" statement?

Asked by 6 years ago

I suck at LUA, however I know enough to realize that there's no switch statement

In my game, I'm trying to create sort of like a "switch" statement, in which right before I delete a object from one side of my GUI, it gets transferred to another side. Think of it as like a card collection and you are switching cards in and out. I'm a fairly new scripter, bare with me ;)

Self explanatory enough, these series of codes automatically redirects cards into your trunk as you get them

cards = player.Cards:GetChildren()

for i, v in pairs(cards) do
local cf = script.Parent.TrunkFrame:clone()
cf.Visible = true
cf.Parent = script.Parent.Cards
cf.Image = v.Texture
cf.CardName.Text = v.Name
cf.Position = UDim2.new(3.80,0,count/5,0)
local c = cf
local gr = v

This series of code makes it so that when I press the "Switch" button, the card would get deleted from the Trunk. Can someone help me with how I can manipulate this function to replicate the card on my Deck before deleting?

cf.Switch.MouseButton1Down:connect(function()
pcall(function() v:destroy() end)
ClearCardList()
LoadCardList()
end)

2 answers

Log in to vote
0
Answered by
Nep_Ryker 131
6 years ago
Edited 6 years ago

What about using "if" and "elseif" ?

Like this?

if Good then
    GoToHeaven()
        -- Not a really good example but try setting it to false again or something like that.
elseif Bad then
    GoToHell()
        -- Not a really good example but try setting it to true again or something like that.
end

-- Don't mind the example pls
Ad
Log in to vote
0
Answered by 6 years ago

Use conditional statement "if"

Something = true
        if Something == true then
                -- script
            Something == false
        elseif Something == false then
                --script
    end
0
just change elseif Something == false then to else :P User#20388 0 — 6y
0
It'd probably not work. Froredion 15 — 6y

Answer this question