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
4 years ago

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

local Slot1 = 1

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

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

Hope I explained enough

0
if, elseif User#17685 0 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 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.

local Slots = {1,1,1,1,1,1}

for i,slotNum in pairs(Slots) do
    if slotNum == 1 then
        ShopFrame.Slot1.ItemName.Text = "TBD"
        ShopFrame.Slot1.Price.Text = "TBD "
        break
    end
end

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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

Answer this question