heya.
So 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 UI through textlabels, 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 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.
If your scrolling labels are dynamic in that there may be more or less than the 4 you’ve specified, it would probably be best to simply generate labels as needed.
You are correct that you’ll want to iterate through your array using pairs.
Example:
local class1Info = {
"This move does this",
"This move does that",
"This punch does this",
--etc...
}
for _,info in pairs(class1Info) do
--generate code for info
--info = the current value in the array
end
Another example:
local classList = {
['Class 1']='Knight',
['Class 2']='Mage'
}
for key,value in pairs(classList) do
print(key..': '..value)
end
Output:
Class 1: Knight
Class 2: Mage
If using a regular array with no keys, the first value will instead be the current iteration position.
1 Like
bumpin’ cause I still having some confusion getting this correctly, so let me just reclarify what i want to achieve with some fancy images this time.
This is the scrolling gui i was referring to, it has multiple textboxes with placeholder text and are organised numerically:
And this is the character select screen:
Once a player clicks on any of these buttons, the scrolling gui would pop up detailing the associated character’s moveset. Basically what i want to achieve is for the scrolling gui to pop up whenever any character is picked, but the textlabels’ text will be changed/updated to show the selected character’s moveset.
Though I’m still not really sure how to achieve this. Any help would be greatly appreciated.