Cycle through messages or menus in random order
The functionality allows access to a fixed list of messages, menu sections or even functions in a random order (without repetitions), showing the user their content or performing a specified action. The cycle of displays can be repeated with the generation of a new random sequence or interrupted after the first round.
As an example, we will take a case of displaying a list of messages in a random order, but once we understand the principle, it can be applied to other cases - for example, to display survey questions in a random order and similar things. After the end of the viewing cycle (when ALL messages are shown), an automatic reset will be performed and a new sorting sequence will be generated. There is NO point in describing any more complex reset mechanics for repeated display - its final implementation is too dependent on a specific project and can hardly be generalized in any way. In general, for a restart, you will need to create a function that brings the system described below to its original state, on your terms.
❖ Acquiring of functionality
All functionality is purchased IN YOUR BOT, for this go to your bot:☞ 🔐Admin | 🧩Extensions
IMPORTANT: The purchase of functionality for the bot is available only to the Creator (owner) of the bot. Admins CANNOT buy functionality!
You will need:
1. Variable - 3 pieces☞ 🔐Admin | 🧩Extensions | 📂Variables
2. Actions - 4 pieces☞ 🔐Admin | 🧩Extensions | 📂Actions
3. Plugin - Macros and Expressions for Buttons☞ 🔐Admin | 🧩Extensions | 📂Buttons
❖ Creating a message enumeration
1. Creating Variables
1.1 Create a Global variable, the value of which will correspond to the number of entities to be sorted (buttons with messages in our case).
Go to your bot:☞ 🔐Admin | 🗄Variables | 📘Global | ➕Create Variable
Name: «msgmax
» - you can choose your own (do not exit the variable editor).
1.1.1 Since global variables are originally text, such a variable must be assigned an initial value. Therefore, without exiting the variable editor, assign it the value 3 (three) - in this example, we will create 3 buttons with messages.
1.2 Create a Simple Tuple (sTuple) variable. The variable will store a Tuple with consecutive numbers in random order.
Go to your bot:☞ 🔐Admin | 🗄Variables | 📚sTuple | ➕Create Variable
Name: «msgtuple
» - you can choose your own.
1.3 Create a Numeric variable. The variable will store the current Tuple Cell number.
Go to your bot:☞ 🔐Admin | 🗄Variables | 📙Numeric | ➕Create Variable
Name: «msgcur
» - you can choose your own.
2. Creating buttons with messages
It is important to understand that the buttons with messages in this guide are chosen for ease of understanding of the example and, in general, can be used as an initial test option. Instead of messages, the buttons can contain entire functions that perform certain actions.
3. Creating the main button for browsing messages
● Select «Action of Numbers»
Variable to change: «msgcur
»
Operation type: Set Value
Value: 0 (zero)
Condition: {%msgcur% == %msgmax%}
Action will do «Restart» - reset the current value to start a new iteration cycle if the counter has reached the maximum value of buttons with messages.
If «Restart» is not needed, INSTEAD of the first action you need to add a Button Condition - {%msgcur% < %msgmax%}
with an error message.
● Select «Action of Numbers»
Variable to change: «msgtuple
»
Operation type: Set Value
Value: {stuple_rlist(1, %msgmax%)}
- Tuple filling function.
Condition: {%msgcur% == 0}
Action creates a list of numbers in random order, ranging from 1 to «msgmax
» (maximum number of buttons from the global variable). Will only work in a new cycle - if «msgcur
» (current value) is zero.
● Select «Action of Numbers»
Variable to change: «msgcur
»
Operation type: Change Value
Value: 1 (one)
Condition: no
Action "counts" the messages shown, so that the first Action can know when to start the next cycle.
● Select «Action of Command»
Command: «/btn{stuple_get(%msgtuple%, %msgcur%)}
» - function of requesting data from the Tuple.
Condition: no
Action calls a button with a message by command with a number contained in the Tuple Cell corresponding to the counter in the variable «msgcur
».
Thus, the user will be presented with a single-button functionality for shuffling through messages from hidden buttons. The user will be able to go through all the button messages in random order, after which the cycle will be automatically reset and a new random display sequence will be generated. Messages within the cycle will not be repeated.