Module 5 · In Studio · challenge 2 of 2 in this lesson
challenges/work/ui_react.luau exports reduce(state, action) and label(name, price, pending, packReady)
A test in Studio grades it and prints a pass code.
Open
Level 3, Professional
Challenge
Write the shop's reducer and its label function in the learner file challenges/work/ui_react.luau (start from the m14-ship tag in the game repo to get challenges/work/ui_react.luau and challenges/ui-react.luau). The test needs no React-lua runtime and runs on pure Luau. The written solution is challenges/solutions/ui-react.md.
- Start from
- The game at milestone m14 (download)
- Grade it
- In Studio, press Play, then run
game.ServerScriptService.RunGameTests:Invoke("ui-react", "ui-react-reducer")in the server command bar. Copy the pass code from Output.
Done means
- challenges/work/ui_react.luau exports reduce(state, action) and label(name, price, pending, packReady)
- reduce(state, action) returns a state shaped { open, pending, message } and handles open, buy, feedback, close; unknown actions return the same table, and the input state is never mutated
- buy sets pending to the item and clears any old message; feedback clears pending and sets message; close clears open, pending and message
- label returns "Name\nWaiting" when pending == name, "Coin Pack\n50 coins" or "Coin Pack\nset COIN_PACK_PRODUCT_ID" for CoinPack, and "Name\n<price> coins" otherwise
- challenges/ui-react.luau prints TEST PASS for every check