ainslec / adventuron-issue-tracker

Adventuron Issues Tracker
4 stars 0 forks source link

[FEATURE] 'baking' in dynamic values into a choice payload #459

Closed nww02 closed 2 years ago

nww02 commented 3 years ago

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.

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()) 
         { :print {("You chose "+item()+"." )} };
      }
      :choose;
   }
}

locations {
   my_location : location "You are in a room.";
}

When you make a selection, the result is, of course, that the term "item()" is out of scope, and results in an error. image

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...

ainslec commented 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.";
}