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

I am trying to do a very strange match up between variables in a loop, may i have help?

Asked by 7 years ago
Edited 7 years ago

Lets say for example I have a frame and in that frame is a bunch of ImageButtons and in those ImageButtons are a bunch of Values and if those values were different like 1,2,3,4,5,6 how would i create a loop to find 1,2 or 3,4 or 5,6? (In the scrolling frame, there are buttons and in those buttons are values like 1,2,3,4,5)

Any Help? This is the script i created:

(NewCounter is the incrementing value)

01repeat wait()
02for _, v in pairs(script.Parent.Parent.Parent.ScrollingFrame:GetChildren(firstValue, secondValue)) do
03    if v:FindFirstChild("NewCounter") then
04        print("Passed 1")
05         NewCounter = v:FindFirstChild("NewCounter")
06         OtherCounter = v:FindFirstChild("NewCounter")
07        if NewCounter.Value == firstValue then
08            print("Passed 2")
09            firstValue = firstValue + 1
10            secondValue =secondValue + 1
11            print(OtherCounter.Value)
12            if OtherCounter.Value == secondValue then
13                print("Passed 3")
14                NewCounter.Value = OtherCounter.Value
15                NewCounter.Parent.Position = OtherCounter.Parent.Position
View all 21 lines...

Any help would be great, tell me if I need to add something more or if something is wrong with this question...

1 answer

Log in to vote
2
Answered by 7 years ago

It's a bit ambiguous what you want, but here's a few options:

01local sf = script.Parent.Parent.Parent.ScrollingFrame
02--Get children from firstValue to secondValue
03local newCounter
04local imageButtons = {}
05for _, v in ipairs(sf:GetChildren()) do
06    newCounter = v:FindFirstChild("NewCounter")
07    if newCounter and newCounter.Value >= firstValue and newCounter.Value <= secondValue then
08        table.insert(imageButtons, v)
09    end
10end
11--If you have named each ImageButton in a formulaic way, ex "Image1", "Image2", etc, you can just do this:
12local imageButtons = {}
13for i = firstValue, secondValue do
14    table.insert(imageButtons, sf["Image" .. i]) -- assumes that the ImageButton will always exist
15end
View all 38 lines...
2
These seems about right, thank you.. greatneil80 2647 — 7y
1
ur face seems about right neil Gey4Jesus69 2705 — 6y
0
thx greatneil80 2647 — 5y
Ad

Answer this question