Built-in Variables

Built-in variables are a type of global variable, but their values are not only used globally.

The following are examples of built-in variables divided up by their scope.

Local Scope

$~

The information about the last match in the current scope (MatchData object). Setting this variable changes the values of $&, $1 ... $9, etc.

Identical to Regexp.last_match.

$&

The string matched by the last successful pattern match in this scope, or nil if the last pattern match failed.

Identical to Regexp.last_match[0]

$1
$2
$3 ...

Contains the subpattern from the corresponding set of parentheses in the last successful pattern matched, or nil if the last pattern match failed.

Identical to Regexp.last_match[1], Regexp.last_match[2], ...

Global Scope

$!

Information on the latest exception. Set with raise.

$DEBUG

The debug mode flag. RGSS sets this flag during playtesting.

There are some differences in exception behavior, etc., while in Ruby's debug mode, but you need not be concerned about them in RGSS.

Converted from CHM to HTML with chm2web Pro 2.85 (unicode)