Contents

Support Managers

Aerielle Kiyori
English
offline
Anomelli Mellow
English
offline
show offline managers  
English, Hindi, Russian  

SBSL User Variables

Have a question? Ask at SmartBots DevPortal!

DevPortal is a blog and forum for developers. Ask your questions to get a prompt reply!

Continue to DevPortal

SBSL supports two types of variables:

  • pre-defined variables: the ones which come automatically with SBSL Events,
  • user variables: the ones discussed in this section.

User variables

User variables are script-wide variables which hold their values for unlimited time. Here's the short example of SBSL code:

# Define user variables
var $my_counter
var $last_contact
 
chat_message {
  # increase the counter
  $my_counter++
  set $last_contact $speaker_name
 
  # report to the owner
  im Glaznah Gassner Chat messages received so far: $my_counter, last message by $last_contact
}

Definition

Each user variable much be defined before usage. The variable is being defined above all events using the var keyword.

var $my_counter

Setting the value

There are two ways to set the variable value:

  1. increment: ++ operator.
    This operation increases the variable by 1. If variable value was not a number, this converts it to number 1.
  2. set to specific value: set keyword.
    You can use the pre-defined and user variables to compose the resulting value.
$my_counter++
set $last_contact $speaker_name

Using the variable

The user variable can be used as any other system variable within a command:

im Glaznah Gassner Chat messages received so far: $my_counter, last message by $last_contact

Variable life time

The variable value is being stored forever, despite of bot restarts, expirations or other factors.