How would I script this reusable moveset list for each class in my fighting game?

Hi. I’m making a character/class select screen for my fighting game and when you select a class it shows their movelist on a scrolling frame through textlabels, which looks like this:
image

Character select screen:
image

I want to re-use this scrolling frame rather than making a scrolling frame with textlabels for each class’ movesets, but I’m trying to figure out how I’d go about this. I have a semi-idea, but can’t really figure out how I’d go about it.

Basically, I chose to store each move description for a class as a separate string inside a table for each class. Like this:

local class1Info = {
     "This move does this",
     "This move does that",
     "This punch does this",
     etc...
}

local class2Info = {
     "This move does that move woah.",
     "This move activates that."
     etc...
}

And i would also have a table for each textlabel in the scrolling UI:

local labelTable = {
    Selectscreen.ScrollingUI.Label1,
    Selectscreen.ScrollingUI.Label2,
    Selectscreen.ScrollingUI.Label3,
    Selectscreen.ScrollingUI.Label4,
    etc
}

I think there might be a way to go about this but I’m not too sure. Maybe a for loop? Any help would be greatly appreciated.

To loop through a table’s contents you can use a for loop like this

local tbl = {
"foo",
"bar",
"baz"
}

for index, value in next, tbl do
    print(index, value)
end
-- 1  foo
-- 2  bar
-- 3  baz

So in your case you could loop through the table, clone the label you want to use, change the text and then parent it to the scrolling frame.

Here’s some pseudocode:

local class1Info = {
    "E - Uppercut",
    "Q - Slam",
    "T - Throw rock"
}

for _, text in next, class1Info do
    local newLabel = exampleLabel:Clone()
    newLabel.Text = text

    newLabel.Parent = scrollingFrame
end
1 Like

I believe I get what you’re saying, though I’m not sure how I can get the textlabel table and the order it’s in.