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

01cards = player.Cards:GetChildren()
02 
03for i, v in pairs(cards) do
04local cf = script.Parent.TrunkFrame:clone()
05cf.Visible = true
06cf.Parent = script.Parent.Cards
07cf.Image = v.Texture
08cf.CardName.Text = v.Name
09cf.Position = UDim2.new(3.80,0,count/5,0)
10local c = cf
11local 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?

1cf.Switch.MouseButton1Down:connect(function()
2pcall(function() v:destroy() end)
3ClearCardList()
4LoadCardList()
5end)

2 answers

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

What about using "if" and "elseif" ?

Like this?

1if Good then
2    GoToHeaven()
3        -- Not a really good example but try setting it to false again or something like that.
4elseif Bad then
5    GoToHell()
6        -- Not a really good example but try setting it to true again or something like that.
7end
8 
9-- Don't mind the example pls
Ad
Log in to vote
0
Answered by 7 years ago

Use conditional statement "if"

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

Answer this question