Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SET

Assign values to variables in BASIC dialogs.

Syntax

SET variable = value

or simply:

variable = value

Parameters

ParameterTypeDescription
variableIdentifierVariable name to assign to
valueAnyValue to assign (string, number, boolean, array, object)

Description

The SET keyword assigns values to variables within BASIC dialog scripts. Variables are dynamically typed and can hold any type of value. The SET keyword is optional - you can use direct assignment with =.

Variables are scoped to the current dialog execution and persist throughout the conversation session until explicitly changed or the session ends.

Examples

Basic Assignment

SET name = "John Doe"
SET age = 25
SET is_premium = true
SET score = 98.5

Direct Assignment (without SET)

name = "Jane Smith"
count = 0
message = "Welcome!"

Array Assignment

SET colors = ["red", "green", "blue"]
SET numbers = [1, 2, 3, 4, 5]
SET mixed = ["text", 123, true]

Object/Map Assignment

SET user = {
    "name": "Alice",
    "email": "alice@example.com",
    "age": 30,
    "active": true
}

Dynamic Values

SET current_time = NOW()
SET user_input = HEAR "What's your name?"
SET calculated = price * quantity * tax_rate
SET formatted = FORMAT("Hello, {0}!", username)

Variable Types

BASIC supports these variable types:

  • String: Text values
  • Number: Integers and decimals
  • Boolean: true/false
  • Array: Ordered lists
  • Object: Key-value maps
  • Null: Empty/undefined

Variable Naming

Valid variable names:

  • Start with letter or underscore
  • Contain letters, numbers, underscores
  • Case-sensitive
  • No reserved keywords

Examples:

SET userName = "John"
SET user_name = "John"
SET _private = true
SET value123 = 456
SET firstName = "Jane"

Invalid names:

' These will cause errors
SET 123name = "error"      ' Starts with number
SET user-name = "error"    ' Contains hyphen
SET if = "error"           ' Reserved keyword

Variable Scope

Session Variables

Regular variables exist for the session:

SET session_data = "persists during conversation"

Global Variables

Use special prefixes for broader scope:

SET $global_var = "accessible across dialogs"
SET @bot_var = "bot-level variable"

Temporary Variables

SET _temp = "temporary use"
' Prefix with underscore for temporary/internal use

Type Conversion

Variables automatically convert types when needed:

SET text = "123"
SET number = text + 0       ' Converts to number: 123
SET back_to_text = number + ""  ' Converts to string: "123"
SET boolean = number > 100  ' Converts to boolean: true

Operations on Variables

String Operations

SET full_name = first_name + " " + last_name
SET uppercase = UPPER(name)
SET length = LEN(message)
SET substring = MID(text, 1, 5)

Numeric Operations

SET sum = a + b
SET difference = a - b
SET product = a * b
SET quotient = a / b
SET remainder = a MOD b
SET power = a ^ b

Array Operations

SET first = colors[0]
SET last = colors[LEN(colors) - 1]
colors[1] = "yellow"  ' Modify array element
SET combined = array1 + array2  ' Concatenate

Object/Map Operations

SET email = user["email"]
SET age = user.age
user["status"] = "active"
user.last_login = NOW()

Conditional Assignment

SET status = IF(score >= 70, "pass", "fail")
SET discount = IF(is_member, 0.2, 0.1)
SET greeting = IF(hour < 12, "Good morning", "Good afternoon")

Common Patterns

Counter Variables

SET counter = 0
FOR i = 1 TO 10
    counter = counter + 1
NEXT

Flag Variables

SET is_complete = false
' ... process ...
SET is_complete = true

Accumulator Variables

SET total = 0
FOR EACH item IN cart
    total = total + item.price
NEXT

State Variables

SET state = "initial"
' ... logic ...
SET state = "processing"
' ... more logic ...
SET state = "complete"

Best Practices

  1. Use descriptive names: customer_email instead of e
  2. Initialize variables: Set initial values before use
  3. Use consistent naming: camelCase or snake_case
  4. Avoid global pollution: Use local variables when possible
  5. Clean up large variables: Set to null when done
  6. Document complex variables: Add comments
  7. Validate before use: Check if variable exists

Error Handling

' Check if variable exists
IF EXISTS(user_data) THEN
    SET name = user_data.name
ELSE
    SET name = "Guest"
END IF

' Safe assignment with default
SET value = GET_VALUE_OR_DEFAULT(config.setting, "default")

Memory Management

' Clear large variables when done
SET big_data = LOAD_FILE("large.json")
' ... use big_data ...
SET big_data = null  ' Free memory
  • GET - Retrieve data from external sources
  • HEAR - Get user input into variable
  • FORMAT - Format values for assignment
  • SET BOT MEMORY - Persistent storage

Implementation Notes

Variables are stored in the BASIC engine’s scope map and persist for the duration of the dialog execution. The SET keyword is syntactic sugar - the parser treats both SET x = y and x = y identically.