« Use Prompt » : différence entre les versions

De Wiki Let's Role
Neo-Teyrall (discussion | contributions)
premier jet sans les image
 
Neo-Teyrall (discussion | contributions)
les image sont ajouter
Ligne 1 : Ligne 1 :
= Prompts =
In Let's Role, '''prompts''' are used to display a window showing text or a form to collect information.   
In Let's Role, '''prompts''' are used to display a window showing text or a form to collect information.   
This is very useful to ask for confirmation, or to request bonuses or penalties related to a roll.
This is very useful to ask for confirmation, or to request bonuses or penalties related to a roll.
Ligne 17 : Ligne 16 :


Note: you can trigger a prompt with any other event in your script.
Note: you can trigger a prompt with any other event in your script.
[[Fichier:Tuto prompt tutorial view 1.png|vignette]]


=== Build a prompt view ===
=== Build a prompt view ===
Ligne 34 : Ligne 34 :


The third argument is optional, but allows you to close the prompt when the ''Continue'' button is clicked.
The third argument is optional, but allows you to close the prompt when the ''Continue'' button is clicked.
 
[[Fichier:Tuto prompt example 1.png|vignette]]
  const promptTutorial = function(sheet){
  const promptTutorial = function(sheet){
     let tutorial_view = "view_prompt_tutorial";
     let tutorial_view = "view_prompt_tutorial";
Ligne 48 : Ligne 48 :
A chained tutorial shows several pages in sequence.
A chained tutorial shows several pages in sequence.
When you click ''Continue'', the next page is displayed.
When you click ''Continue'', the next page is displayed.
[[Fichier:Tuto prompt tutorial view 2.png|vignette]]


=== Create a button ===
=== Create a button ===
Ligne 72 : Ligne 73 :
== Tutorial 3: Prompt as a form ==
== Tutorial 3: Prompt as a form ==
A prompt can also be used as a '''form''' to collect information, fill fields, or add variables to a roll.
A prompt can also be used as a '''form''' to collect information, fill fields, or add variables to a roll.
[[Fichier:Tuto prompt form button.png|vignette]]


=== Create a button ===
=== Create a button ===
Prepare a button that will open the prompt, just like a roll [[button]].  
Prepare a button that will open the prompt, just like a roll [[button]].  
[[Fichier:Tuto prompt form.png|vignette]]


=== Create the prompts ===
=== Create the prompts ===

Version du 27 septembre 2025 à 23:17

In Let's Role, prompts are used to display a window showing text or a form to collect information. This is very useful to ask for confirmation, or to request bonuses or penalties related to a roll.

To create and use a prompt, you need to use a script and build a view.

This page shows three tutorials, from the simplest to the most advanced:

  • a tutorial to create a prompt that simply displays text (for tutorials or tooltips),
  • a tutorial to chain multiple prompts to build a multi-page tutorial,
  • a tutorial to use prompts as forms to input modifiers or additional dice in a roll.

Tutorial 1: Create a simple prompt

Create a button

The first step is to create a button that triggers the script.

Note: you can trigger a prompt with any other event in your script.

Build a prompt view

The prompt that appears is actually a view you need to build.

The ID of this view must be defined properly, since it will be used in the script.

Script

Here is a script that manages the prompt display. This function does three things:

  • detects the click on the button,
  • shows the prompt,
  • handles the closing of the prompt.

Most of these actions are handled by the sheet.prompt(...) function.

The third argument is optional, but allows you to close the prompt when the Continue button is clicked.

const promptTutorial = function(sheet){
   let tutorial_view = "view_prompt_tutorial";
   let tutorial_title = "prompt tutorial";
   let tutorial_button = sheet.get("display_tutorial_1");
   
   tutorial_button.on("click", function(){
       sheet.prompt(tutorial_title, tutorial_view, function(){});
   })
}

Tutorial 2: Chained prompts

A chained tutorial shows several pages in sequence. When you click Continue, the next page is displayed.

Create a button

As in the first tutorial, create a button to trigger the prompt.

Create the views

Each page of the tutorial must be created as a separate view.

Script

The display of the next page is requested in the closing function of the previous prompt.

const promptTutorial2 = function(sheet){
 let tutorial_view_1 = "view_prompt_tutorial";
 let tutorial_view_2 = "view_prompt_tutorial_2";
 let tutorial_title = "prompt tutorial";
 let tutorial_button = sheet.get("display_tutorial_2");
 
 tutorial_button.on("click", function(){
     sheet.prompt(tutorial_title + " (1/2)", tutorial_view_1, function(){
         sheet.prompt(tutorial_title + " (2/2)", tutorial_view_2, function(){})
     });
 })
}

Tutorial 3: Prompt as a form

A prompt can also be used as a form to collect information, fill fields, or add variables to a roll.

Create a button

Prepare a button that will open the prompt, just like a roll button.

Create the prompts

Build your prompts with appropriate input fields (TextInput, NumberInput, etc.).

For example, a prompt that asks for the roll name and a modifier.

Prepare a script

The script must include a closing function to handle and process the entered data.

You can also define an initialization function to configure the display (e.g. pre-fill some fields).

const initPromptExample = function (sheet) {
  log("START init prompt");
 
  // Prompt initialization
  const promptInitialization = function (prompte_view) {
      log("START prompt initialization");
      prompte_view.get("prompt_name").value(sheet.get("prompt_name").value());
      prompte_view.get("prompt_roll").value(sheet.get("prompt_roll").value());
      log("END prompt initialization");
  }

  // Process prompt results
  const promptAccepte = function (prompte_results) {
      log("START prompt results");
      let roll = prompte_results.prompt_roll;
      log("mod : [" + prompte_results.prompt_modificator + "]");
      if (prompte_results.prompt_modificator != undefined && prompte_results.prompt_modificator != 0) {
          roll += "+" + prompte_results.prompt_modificator + "[Modifier]";
      }
      log("-- roll : " + roll);
      Dice.roll(sheet, roll, prompte_results.prompt_name);
      log("END prompt results");
  }

  // ID of the view displayed as prompt
  let prompt_view = "view_prompt";
  let prompt_name = "";
  let roll_button = sheet.get("prompt_roll_button");

  // Show the prompt when the button is clicked
  roll_button.on("click", function () {
      sheet.prompt(prompt_name, prompt_view, promptAccepte, promptInitialization);
  });
  log("END init prompt");
}