v3 · Activity 9 of 9 · table-identity · references · nested-tables · 12 min Runs here
Assigning local preview = original gives both names the same table. It does not duplicate contents. Two separately created tables with equal-looking contents are different identities.
table.clone makes a shallow copy. Nested tables inside the copy still refer to the original nested tables.
previewLoadout(saved, extra) returns {originalCount, previewTools}. Append extra only to a copy of saved.tools, preserving saved.tools. Keep the final return shown in the starter so the checker can call or inspect your result.
Interface: previewLoadout(saved:{tools:{string}},extra:string) -> summary table
| Input | Expected |
|---|---|
Saved hammer{ tools = { "Hammer" } }, "Brush" | { originalCount = 1, previewTools = { "Hammer", "Brush" } } |
Empty saved loadout{ tools = {} }, "Lamp" | { originalCount = 0, previewTools = { "Lamp" } } |
local saved = { tools = {"Hammer"} }
local preview = table.clone(saved)
preview.tools = table.clone(saved.tools)
table.insert(preview.tools, "Brush")
return { originalCount = #saved.tools, previewCount = #preview.tools }Copying both the outer table and the tools sequence lets the preview change independently.
New syntax: table.clone()
Your explanation is a self-check. Exact wording is not automatically graded.
Assigning local preview = original gives both names the same table. It does not duplicate contents. Two separately created tables with equal-looking contents are different identities.
table.clone makes a shallow copy. Nested tables inside the copy still refer to the original nested tables.
Copy only the nested layer you plan to change for this activity. Arbitrary deep copying needs policies for cycles, functions and special engine values; this small example does not claim to solve all of them.
Select a word or symbol in this authored example. Your editor draft stays unchanged.
previewLoadoutsaved, extra
preview table.clonesaved
table.insertpreview.tools, extra
originalCount saved.tools, previewTools preview.tools
previewLoadoutThis is a private experiment copy. It does not replace your answer or complete the activity.
These inputs apply when your scratchpad returns the function described by the activity interface.
Your output will appear here.
Replace this code with the starter? Download your draft to keep a copy.
Your output will appear here.
Sign in with RoCreators to save private progress across devices. Community verification is separate.