Register to post in forums, or Log in to your existing account
 

 Related 
Contents
See also:
  Introduction to Variables
Feature Reference
  Aliases
  Macros
  Variables
    Local Variables
    Variable Types
    Indirect Variables
  Functions
  Classes
  Triggers
  Buttons
  Gauges
  Paths
  Menus
  Events
  Modules
  Windows
  Packages
  Shared Package Library
  Package Editor
  Docked Windows
  Customizeable Toolbars
  Sessions
  Expressions
  Automapper Module
  Database Module
  Syntax Checking
  Tab Completion
  Status items
  Preferences
  Simutronics Support
  Pueblo Emulation
  Keyboard shortcuts
  MXP
  Threads
  ATCP
  Script Debugger
  Timestamps
  Lua Scripting
Related Links:
  #T+
  Terminology
  Feature Summary
  Scripting
  Functions
Variables [[cmud_variables]] 
Like in traditional programming languages, Variables are containers that hold a value. For example, just typing:

a = 123

will assign the number 123 to the variable named "a".

To access the value of a variable, precede its name with the @ character. Note that this is different than in PHP or TINTIN where variables start with a $ character. (CMUD uses the $ character for local variables). For example:

#SHOW @a

You can also use the #VARIABLE command to assign a variable:

#VAR a 123

This is an older syntax, but it supports several advanced features such as Indirect variable assignment.

Expressions and functions can be used within the variable assignment. For example:

b = @a+1

would assign the number 124 to the @b variable. To force an expression to be evaluated, you can enclose the expression in () parenthesis. To assign a literal string value, enclose the string in " quotes. To perform variable expansion but *not* expression evaluation, enclose the value in {} braces. Here are several examples:
Code:
b = @a+1  // 124 assigned to @b
b = (@a+1)  // same as above
b = "@a+1"  // assigns the literal string "@a+1" to @b
b = {@a+1}  // assigns the string "123+1" to @b

In the first two cases, the @b variable is set to Auto-typed. In the 3rd line using " the @b variable is set to a "literal string" type. In the 4th line using the {} the @b variable is set to a "string (expanded)" type to show that variable expansion is allowed.

In general, be sure to put " quotes around literal strings. If you want a string value that allows variable expansion, use {} instead of " quotes. This is similar to PHP in which variable expansion is allowed within " quotes but not within ' single quotes. CMUD " quotes are like the PHP ' single quotes. CMUD {} braces are like the PHP " double quotes.
Viewer Comments [0 - Post your comments]

Jump to:  

© 2009 Zugg Software. Hosted by Wolfpaw.net