$variables
Variables are the foundation of data management in Rhappsody applications. They provide a simple, intuitive way to store and manipulate information throughout your app.
key concepts
naming conventions
- Variables are prefixed with a
$
symbol (e.g.,$my-var
) - All variables are global to the entire app
- Variable names are case sensitive -
$my-var
is different from$My-Var
- Convention: use lowercase letters, numbers, and dashes (e.g.,
$user-name
,$item-count
)
best practices
- Use descriptive, meaningful names that clearly indicate the data’s purpose
- Longer names are encouraged for clarity (e.g.,
$customer-email
instead of$email
) - Ensure variable names are unique across your entire application
- Remember that all variables share the same global scope
variable types
string
Text values enclosed in double quotes. Use single quotes when the value contains double quotes.
$user-name = "John Doe"
$message = 'He said "Hello!"'
number
No distinction between integers and floats.
$age = 25
$price = 19.99
$temperature = -10.5
boolean
Accepts multiple formats for better readability:
true
/false
yes
/no
on
/off
$premium-member = yes
$automatic-renewal = off
$is-active = true
date
Dates use the YYYY-MM-DD
format.
$today = 2025-01-15
$deadline = 2025-12-31
time
Times use the HH:MM:SS
format.
$start-time = 09:00:00
$appointment = 14:30:00
objects
Objects use dot notation to organize related data. They can only be nested one level deep.
$user.name = "Alice"
$user.age = 30
$user.email = "[email protected]"
$product.title = "Widget"
$product.price = 29.99
$product.in-stock = yes
You don't need to initialize an object before using it. Setting $user.name = "John"
automatically creates the $user
object if it doesn't exist.
Objects can only be nested one level deep. $user.address.city
is NOT allowed.
examples
Here’s a simple example showing various variable types in action:
// User information
$user-name = "Sarah Johnson"
$user-age = 28
$is-premium = yes
$signup-date = 2024-03-15
// Product details
$product.name = "Premium Widget"
$product.price = 49.99
$product.available = true
$product.release-date = 2024-01-01
// Settings
$dark-mode = on
$notifications-enabled = yes
$last-login-time = 14:30:00
next steps
Now that you understand variables, you can: