Recap - Character Sheet
Part of the Logic & Flow section of Coddy's Lua journey — lesson 4 of 54.
Challenge
EasyWrite a function displayCharacterStats that takes a character table and returns a formatted string displaying all stats.
Use pairs() to iterate through all key-value pairs in the character table and build a string where each line shows a stat name followed by its value in the format key: value. Each stat should be on a separate line.
Parameters:
character(table): A dictionary-style table where keys are stat names (strings) and values are stat values (numbers or strings)
Returns: A string with each stat on a separate line. Format:
stat1: value1
stat2: value2
stat3: value3Try it yourself
function displayCharacterStats(character)
-- Write code here
end
All lessons in Logic & Flow
1Advanced Table Iteration
Iterating with pairs()Iterating with ipairs()pairs() vs. ipairs()Recap - Character Sheet2More Table Library Functions
table.concat()table construction & unpack()table.sort()Custom Sorting with FunctionsRecap - High Score Board