Closed nww02 closed 2 years ago
I think you are looking for "payload":
start_at = my_location
collections {
list_1 : list {
items = ["Option 1","Option 2","Option 3"];
};
}
on_command {
: match "test -" {
:iterate "list_1"
{
:add_choice text->("Select "+item()) payload -> (item())
{ :print {("You chose "+choice_payload()+"." )} };
}
:choose;
}
}
locations {
my_location : location "You are in a room.";
}
I'm attempting to create a dynamic choice list based on a list of options. Unfortunately, I cannot dynamically generate the choices to select an item from the list because the index selection is deferred until later, at which point the value has changed.
When you make a selection, the result is, of course, that the term "item()" is out of scope, and results in an error.![image](https://user-images.githubusercontent.com/46803513/124591674-7b2b8180-de54-11eb-89c9-19f1c658758c.png)
Attempting to get around it with index() or a dynamic integer or dynamic string just doesn't work, because it is calculated too late.
I've tried using lazy="false" and lazy="true", but neither seem to force the evaluation early. I'm not sure what the "lazy" param is meant to do, but I would guess that when set to "false", any time something dynamic is used, its value is calculated at that moment, and the value baked into the payload, rather than the name of the variable...