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

Trying To Find True In IF Statement?

Asked by
Lacin1a 12
5 years ago

I Am Trying To Change A TextLabel If Its True Without Using A Lot Of IF Statements

1local Slot1 = 1
2 
3if Slot1 or Slot2 or Slot3 or Slot4 or Slot5 or Slot6 == 1 then
4    ShopFrame.Slot1.ItemName.Text = "TBD"
5    ShopFrame.Slot1.Price.Text = "TBD "
6end

I want to make it so I can change Slot1 doesn't get changed.

Hope I explained enough

0
if, elseif User#17685 0 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Rather than repeating the same thing 6 times, you could use an array than loop through that. What this does instead of having variables named Slot1, Slot2, Slot3, Slot4, etc, you have an array called Slots, and to reference each slot you can do Slot[1], and then use the for loop shown below to check if any of the slots equal true.

1local Slots = {1,1,1,1,1,1}
2 
3for i,slotNum in pairs(Slots) do
4    if slotNum == 1 then
5        ShopFrame.Slot1.ItemName.Text = "TBD"
6        ShopFrame.Slot1.Price.Text = "TBD "
7        break
8    end
9end
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Here is one solution you can try, It's pretty simple, should definitely work. :)

1if Slot1 == 1 or Slot2 == 1 or Slot3 == 1 or Slot4 == 1 or Slot5 == 1 or Slot6 == 1 then
2    ShopFrame.Slot1.ItemName.Text = "TBD"
3    ShopFrame.Slot1.Price.Text = "TBD"
4end

Answer this question