You can set the value of a variable using the set command. If the variable doesn't exist when you set it, then it will be created. Valid variable names contain only the characters a-z, A-Z, 0-9, underscore (_), and period (.).
There are two forms of the set command: set <variable> = [string] set <variable> = [expression]
The first form sets the variable to a string. The string must be delimited by quotes, but you can use the backslash to escape a character if needed.
Examples:
set variable_one = "Boot Scriptor is now" set variable_two = "called \"CD Shell\"."
The second form basically evaluates a mathematical expression (you can read more about expressions here) and then stores the result into the variable. All variables are represented internally as strings, so this essentially just calculates the result of the expression and then converts the number into a string.
Example:
set myVar = 1 + 2
Using Variables (reading)
When you want the value of a variable, you use the variable name preceded by the dollar sign. Optionally, you can enclose the variable name in parenthesis.
Examples:
print "$variable_one $(variable_two)" set myVar = $myVar + 5
The dollar sign also has the ability to escape characters, so $$, $;, and $# can be used to get '$', ';', and '#' without CD Shell thinking you are ending a command or starting a comment, etc.
Example:
# This prints out "Baseball"
set one = "Ba"
set two = "seb"
print "$one$(two)all"
Built-In Variables
Modules can define their own variables as well. Some of these module-defined variables actually take the place of commands previously found in Boot Scriptor, such as the color command. Whereas all user-defined variables are both readable and writable, the built-in ones may be read-only or write-only. Also whereas all user-defined variable names are case-sensitive, most of the modules' variable names are not. The following is a list of all built-in variables.
Variable List
$appName
R
basic.csm
This variable returns the program name ("CD Shell").
$blinkMode
R
W
basic.csm
This variable can be used to check or set the flag that controls blinking text.
$boldColor
R
W
basic.csm
This variable can be used to check or set the text highlight color. You can check or set this variable using the color function as follows:
set boldColor = color[green on black] if $boldColor == color[green on black] then print "The bold color is green."
$dateDay
R
basic.csm
This variable returns the current day.
$dateMonth
R
basic.csm
This variable returns the current month.
$dateYear
R
basic.csm
This variable returns the current year.
$fda $fdb
R
boot.csm
These variables return the BIOS device identifier for the first two floppy disk drives. They can be used as convenient shortcuts when using the boot command or bootCheck function.
$hda $hdb $hdc $hdd
R
boot.csm
These variables return the BIOS device identifier for the first four hard disk drives. They can be used as convenient shortcuts when using the boot command or bootCheck function.
$lastChar
R
script.csm
This variable stores the last raw character pressed. It is mainly used to build character strings, as seen in the example below.
set string = ""
build_string: getkey if $lastKey == key[enter]; then goto done set string = "$(string)$lastChar" goto build_string
done: print "The whole string is: $string"
$lastKey
R
W
script.csm
This variable stores the numeric keycode of the last key pressed. You can check or set this variable using raw hex codes, or the key function as follows.
if $lastKey == key[enter] then print "You pressed the enter key."
$MD5
R
W
basic.csm
This variable is a little different from the others, as it MD5 encodes whatever you write to it and returns the checksum (hash) value upon subsequent reads. It is mainly intended to encrypt passwords so that you can control access to menu options.
# User inputs a string (see $lastChar variable) into $password.
# Here we check against the password "administrator" (very poor choice) # which has an MD5 value as shown below. set password_hash = "200CEB26807D6BF99FD6F4F0D1CA54D4"
# We encode the password given by the user, and then check for a match. set MD5 = "$password" if icompare["$password_hash" "$MD5"] then print "Password match!" else print "Invalid password!"
$mouse
R
mouse.csm
This variable indicates whether or not there is a mouse connected and available for use. It returns true (1) if the mouse is available, and false (0) if is not.
Currently CD Shell only supports PS/2 compatible mice (enable Legacy Mouse in BIOS if you have a USB mouse) and the cursor is only visible in text mode.
if $mouse == 1 then print "The mouse is connected." else print "No pointing device detected."
$mouseButtonLeft
R
mouse.csm
This variable indicates whether or not the left mouse button is currently pressed. It returns true (1) if the button is pressed down, and false (0) if is not being pressed.
if $mouseButtonLeft == 1 then print "The left mouse button is being held down." else print "The left button has been released."
$mouseButtonMiddle
R
mouse.csm
This variable indicates whether or not the middle mouse button is currently pressed. It returns true (1) if the button is pressed down, and false (0) if is not being pressed.
if $mouseButtonMiddle == 1 then print "The center mouse button is being held down." else print "The center button has been released."
$mouseButtonRight
R
mouse.csm
This variable indicates whether or not the right mouse button is currently pressed. It returns true (1) if the button is pressed down, and false (0) if is not being pressed.
if $mouseButtonRight == 1 then print "The right mouse button is being held down." else print "The right button has been released."
$mouseColor
R
W
mouse.csm
This variable can be used to check or set the color of the text-mode mouse cursor. You can check or set this variable using the color function as follows:
set mouseColor = color[white on red]
if $mouseColor == color[white on red] then print "The mouse cursor color is red."
$mouseCursorX
R
W
mouse.csm
This variable controls the horizontal location of the mouse cursor. The range is determined by the current display mode.
$mouseCursorY
R
W
mouse.csm
This variable controls the vertical location of the mouse cursor. The range is determined by the current display mode.
$mouseVisible
R
W
mouse.csm
This variable controls whether or not mouse cursor is visible on the screen. A value of 1 indicates that the cursor is currently visible, while a value of 0 indicates that the cursor is hidden.
$overscanColor
R
W
basic.csm
This variable can be used to check or set the display's overscan color. The value you assign to this variable does not set the overscan color directly, rather it selects the DAC register that contains the color information.
$tabSize
R
W
script.csm
This variable controls the distance between tab stops when using the \t escape sequence with the print command. Just set it equal to the number of spaces per tab.
$textColor
R
W
basic.csm
This variable can be used to check or set the default text color. You can check or set this variable using the color function as follows:
set textColor = color[blue on white] if $textColor == color[blue on white] then print "The color is blue."
$textCursorX
R
W
script.csm
This variable controls the horizontal location of the text cursor. You can only set it to values from 0 to 79.
$textCursorY
R
W
script.csm
This variable controls the vertical location of the text cursor. You can only set it to values from 0 to 24.
$timeHour
R
basic.csm
This variable returns the current hour.
$timeMinute
R
basic.csm
This variable returns the current minute.
$timeSecond
R
basic.csm
This variable returns the current second.
$vesa
R
basic.csm
This variable lets you check to see if CD Shell will be able to display CSI images. It returns true (1) if Vesa BIOS Extensions are sufficiently supported, and false (0) if they are not.
$version
R
basic.csm
Returns the program version as a string. (eg. "2.0.0b")
$versionDOS
R
basic.csm
This variable lets you check to see if you're currently in the Script Debugger. It returns true (1) if CD Shell is currently running inside DOS/Windows, and false (0) if not.
$vga
R
basic.csm
This variable lets you check to see if a VGA is installed. It returns true (1) if a VGA adapter is detected, and false (0) if not.