ainslec / adventuron-issue-tracker

Adventuron Issues Tracker
4 stars 0 forks source link

Allow to set a default "choice" for add_choice / choose. #446

Closed ainslec closed 3 years ago

ainslec commented 3 years ago

Add a function to allow to set a default "choice" for : add_choice / : choose. commands.

The most recent choice that has default = "true" will be the default choice, which will be selected if the player presses ENTER.

: add_choice "One" {
}
: add_choice "Two" default = "true" {
}
: add_choice "Three" {
}
: choose; // If player presses enter, select choice "Two"

Another example:

: add_choice "One" {
}
: add_choice "Two" default = "true" {
}
: add_choice "Three" default -> (true) {
}
: choose; // If player presses enter, select choice "Three" (most recent added default)
ainslec commented 3 years ago

Done.

This selected Elf:

start_at = my_location

strings / class : string ;

locations {

   my_location : location "You are in a room.";

}

on_startup {

   : add_choice "Wizard"  {
      : set_string var = "class"  value = "Wizard" ;
   }

   : add_choice "Elf" default = "true"  {
      : set_string var = "class"  value = "Elf" ;
   }

   : add_choice "Mermaid" {
      : set_string var = "class"  value = "Mermaid" ;
   }

   : choose "Choose a class ... " ;
   : press_any_key ;
   : clear_screen;
   : print "Class : {class}";
   : win_game ;
}

And (selected mermaid):

start_at = my_location

strings / class : string ;

locations {

   my_location : location "You are in a room.";

}

on_startup {

   : add_choice "Wizard"  {
      : set_string var = "class"  value = "Wizard" ;
   }

   : add_choice "Elf" default = "true"  {
      : set_string var = "class"  value = "Elf" ;
   }

   : add_choice "Mermaid" default = "true"  {
      : set_string var = "class"  value = "Mermaid" ;
   }

   : choose "Choose a class ... " ;
   : press_any_key ;
   : clear_screen;
   : print "Class : {class}";
   : win_game ;
}