Master conversational programming step by step
Let's start with the classic "Hello World" program. In Whisper, you
use the whisper command to output text.
whisper "Hello, World!"
You can also use other output commands:
show "This also works!"
tell me "So does this!"
just say "And this too!"
hello.wsp and write a program that
displays your name!
Variables in Whisper use natural language. There are multiple ways to create them:
# Method 1: Using "let"
let name be "Alice"
let age be 25
# Method 2: Using "remember that"
remember that score is 100
# Method 3: Using "set"
set level to 5
# Method 4: Using "so"
so points is 50
Display variables:
whisper "My name is " + name
show "I am " + age + " years old"
Get input from users with the ask command:
ask "What is your name?" into username
whisper "Hello, " + username + "!"
ask "How old are you?" into user_age
whisper "You are " + user_age + " years old"
Whisper has two styles of conditionals:
let age be 20
when age greater than 18:
whisper "You are an adult"
or when age equals 18:
whisper "Just turned 18!"
otherwise:
whisper "You are a minor"
let score be 85
is score greater than 60?
yes:
whisper "You passed!"
no:
whisper "Try again"
Comparison operators you can use:
is or equals - Check equalitynot - Check inequalitygreater than or bigger than - Check if
larger
less than or smaller than - Check if
smaller
Whisper offers multiple loop styles:
let count be 1
while count less than 6:
whisper "Count: " + count
increase count by 1
repeat 5:
whisper "Hello!"
# or
do 3 times:
whisper "Hi there!"
make fruits with ["apple", "banana", "orange"]
for each fruit in fruits:
whisper "I like " + fruit
Loop control:
break or stop - Exit the loopcontinue or skip - Skip to next iteration
Create reusable code with functions:
# Define a simple function
define greet:
whisper "Hello from function!"
# Call the function
call greet
# Function with parameters
define greet_person with name:
whisper "Hello, " + name + "!"
call greet_person with "Alice"
# Function that returns a value
define add with a, b:
give back a + b
call add with 5, 3
whisper "Sum: " + __last_result__
Create game characters and objects with natural syntax:
# Create a hero character
there is a hero with health 100, power 50
# Access properties
show hero health
show "Power: " + hero power
# Modify properties
the hero loses 20 health
the hero gains 10 power
show "Health: " + hero health
show "Power: " + hero power
Work with collections of data:
# Create a list
make tasks with ["Buy milk", "Call mom"]
# Add items
add "Study Whisper" to tasks
add "Exercise" to tasks
# Display all items
for each task in tasks:
whisper task
# Remove an item
remove "Call mom" from tasks
Whisper supports all basic math and advanced functions:
# Basic operations
let sum be 10 + 5
let diff be 10 - 5
let product be 10 * 5
let quotient be 10 / 5
# Math functions
let root be sqrt(16)
let power be pow(2, 3)
let absolute be abs(-10)
let rounded be round(3.7)
let biggest be max(5, 10, 3)
let smallest be min(5, 10, 3)
Congratulations! You've learned the basics of Whisper. Here's what to explore next: