[A.L. dev. diary] Help creating a macro! Not reading object as argument.
Hello, lovely community!
I'm polishing the code of Another Life, to try to make it easier to expand in the future. I'll try to explain the functions briefly so you understand where I need help.
PROBLEM TO SOLVE: The buttons to call the next events are coded this way:
<<button "Take a rest">>
<<if $actionsLeft > 0>>
<<set _cands = setup.findEvents({ actionType: "act_rest", initialOnly: true })>>
<<set _pick = setup.pickWeighted(_cands)>>
<<if _pick>><<goto _pick.title>><<else>>No initial rest events available.<</if>>
<<else>>
<<run UI.alert("No actions left. Hit 'Next turn' when you are ready.")>>
<</if>>
<</button>>
PROPOSED SOLUTION: Create a macro so the buttons' code looks this way:
<<button "Go to school">>
<<if $actionsLeft > 0>>
<<nextEvent { action: "act_study" }>>
<<else>>
<<run UI.alert("No actions left. Hit 'Next turn' when you are ready.")>>
<</if>>
<</button>>
PROBLEM FOUND: Macro doesn't seem to be reading the arguments. properly.
- Error code: [nextEvent] Error: First argument must be an object { key _ value }.
- In the macro code, it is located in the
RELATED FUNCTIONS:
- setup.findEvents()
- Input: actionType, phase, location, initialOnly = false, special, persistent = false, random}
- output: Array with the title of all events that match criteria. Has some smart functions to not fail if not all parameters are included.
- setup.pickWeighted()
- Input: Array of event titles (usually from setup.findEvents)
- output: a randomly selected event title (from the provided list) based on their weight.
These two functions have been working wonders when called independently.
MACRO "nextEvent" code:
/* =========================================
MACRO: NEXT EVENT (Navigator) - FIX
Use: <<nextEvent { action: "act_study" } "FallbackPasaje" >>
========================================= */
Macro.add('nextEvent', {
handler: function () {
// 1. OBTAIN ARGUMENTS
// Using "clone" to create copy & avoid error "cannot create property..."
let rawArgs = this.args[0];
let criteria = {};
// Verify it is a valid object before cloning
if (rawArgs && typeof rawArgs === 'object') {
criteria = clone(rawArgs);
} else {
console.error("[nextEvent] Error: First argument must be an object { key : value }.", rawArgs); // <- THIS error pops in the console
return;
}
// REST OF THE CODE.
// To consider, I added some auto complete functions to avoid crashes related with missing arguments.
// for instance, if not defind initialOnly, the macro assumes initialOnly = true, etc.
});
So that's it, I can't figure out why the macro is failing at this point. If you could pinpoint it, I would appreciate it very much :)
Thank you kindly!
Posted Dec 13, 2025, 10:25 AM UTC
12