« Asynchrone play » : différence entre les versions

De Wiki Let's Role
Neo-Teyrall (discussion | contributions)
Page créée avec « Let’s Roll is not designed to be used asynchronously. There is no native way to play asynchronously. However, there are methods to play asynchronously by tracking your players’ actions with a timestamp. This page explains how to set up a timestamp system and how to link it to bindings in order to follow each action performed by your players. '''Getting the date and time''' To obtain the current time, you can use the following function. It gives you the cu... »
 
Neo-Teyrall (discussion | contributions)
Aucun résumé des modifications
 
(2 versions intermédiaires par le même utilisateur non affichées)
Ligne 4 : Ligne 4 :


This page explains how to set up a timestamp system and how to link it to bindings in order to follow each action performed by your players.
This page explains how to set up a timestamp system and how to link it to bindings in order to follow each action performed by your players.
[[Fichier:Date example.png|centré]]


'''Getting the date and time'''
'''Getting the date and time'''
Ligne 29 : Ligne 30 :


'''Writing the message'''
'''Writing the message'''
 
[[Fichier:Chate date.png|vignette]]
The following example shows a view that you can add to one of your tabs.
The following example shows a view that you can add to one of your tabs.


Ligne 44 : Ligne 45 :
– a field to specify your time zone: “date_time_zone”
– a field to specify your time zone: “date_time_zone”


[[Fichier:Message date.png|vignette]]
'''Displaying the message'''
'''Displaying the message'''


Ligne 60 : Ligne 62 :
Once all of this is in place, you can use the following script, which connects everything together.
Once all of this is in place, you can use the following script, which connects everything together.


init = function(sheet) {
    if (sheet.id() === "main") {
        initMain(sheet);
    }
};
const initMain = function(sheet) {
    // Main initialization
    dateMessage(sheet);
};
  const dateMessage = function (sheet) {
  const dateMessage = function (sheet) {
        let date_send_message = "date_send_message";
        let date_send_message = "date_send_message";

Dernière version du 29 novembre 2025 à 00:00

Let’s Roll is not designed to be used asynchronously. There is no native way to play asynchronously.

However, there are methods to play asynchronously by tracking your players’ actions with a timestamp.

This page explains how to set up a timestamp system and how to link it to bindings in order to follow each action performed by your players.

Getting the date and time

To obtain the current time, you can use the following function. It gives you the current date, which is very useful for asynchronous sessions that take place over a week. For longer sessions, use the advanced function (link).

const heure = function (time_zone) {
    const jours = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
    now = Date.now(); // epoc 
    dateBase = new Date("2025-01-06"); // A Monday
    delta = (now - dateBase) / 1000 + time_zone * 60 * 60; //  seconds
    s = delta % 60;
    delta = Math.floor(delta / 60); // minutes
    m = delta % 60;
    delta = Math.floor(delta / 60); // hours
    h = delta % 24;
    delta = Math.floor(delta / 24); // Day
    j = jours[delta % 7];
    return j + " " + h + ":" + (m < 10 ? "0" + m : m);
  }

Sending a timestamped message

To send a timestamped message, you will need to set up a message sender so your players can specify the action they want to perform and the contextual roll.

Writing the message

The following example shows a view that you can add to one of your tabs.

– a field for the action name: id “date_title”

– an area for writing a long message: “date_message”

– a field for the roll title: “date_roll_title”

– a field to enter a roll to perform: “date_roll”

– a button to send the message to the chat: “date_send_message”

– a field to specify your time zone: “date_time_zone”

Displaying the message

You must create a view (id: “view_message”) to display the message in the chat.

It must contain at least:

– a label to display the message text (text = “if(#text = 0, ‘[Text]’, #text)”)

– a label to display the result of the action (text = “if(#roll = 0, ‘[Roll]’, #roll)”)

– a label containing the name of the character who performed the action (text = “if(#perso = 0, ‘[Perso]’, #perso)”)

– a label that contains the date of the action (text = “if(#time = 0, ‘[Time]’, #time)”)

Once all of this is in place, you can use the following script, which connects everything together.

init = function(sheet) {
    if (sheet.id() === "main") {
        initMain(sheet);
    }
};
const initMain = function(sheet) {
    // Main initialization
    dateMessage(sheet);
};

const dateMessage = function (sheet) {
      let date_send_message = "date_send_message";
      let title = sheet.get("date_title");
      let dice_roll = sheet.get("date_roll");
      let roll_title = sheet.get("date_roll_title");
      let message = sheet.get("date_message");
      let button_message = sheet.get(date_send_message);
      let time_zone = sheet.get("date_time_zone");
      // display the message with the roll results 
      const result_message = function (result) {
          log("START : action roll cliked");
          messageChat(sheet, title.value(), message.value(), result.total, time_zone.value());
      }
      // setup the roll
      const button_click = function () {
          log("START : roll cliked");
          let roll = new RollBuilder(sheet);
          if (dice_roll.value() == ""){
              roll = roll.expression("0");
          } else {
              roll = roll.expression(dice_roll.value());
          }
          roll = roll.visibility("all");
          roll = roll.title(roll_title.value());
           // renseigner la fonction automatique
          roll = roll.onRoll(result_message);
          roll.roll();
          log("END : roll clicked")
      }
      button_message.on("click", button_click);
      // The functoin Send the message in the chat. 
      const messageChat = function (sheet, titre, texte, result, time_zone) { 
          let binding_name = sheet.properName() + " : " + titre;
          Bindings.add(binding_name, "sheet", "view_message", function (sheet) { 
              const h = time_complete(time_zone);
              const data = {
                  text: texte,
                  roll: result,
                  perso: sheet.properName(),
                  time: h
              };
              return data;
          })
          Bindings.send(sheet, binding_name); // Send message to chat
          Bindings.remove(binding_name); // Delete the binding
      }
  }