Gosu variables

A Gosu variable is a storage container for a certain type of data. As you create and assign a Gosu variable, you need to consider the type of the variable as well as its value.

Strong typing of variables

If you specify a type for a variable in its declaration in Gosu code, Gosu thereafter considers the variable to be strongly typed. Any attempt to assign an incompatible value to the variable generates a type-mismatch error. Similarly, if you set a value for a variable in the variable declaration, but do not specify the variable type, Gosu strongly types the variable to the type of the provided initial value.

The only way to declare a variable without a strong type is to initialize it with a null value without a specifying a type. However, even if you do not assign a type to a variable in its declaration, the variable takes on the type of the first value assigned to it.

Character set available for variable names

Gosu uses the same rules for variable names as Java and supports a standard ASCII subset for those names. The first character can be:
  • A letter
  • $
  • _
Subsequent characters can be:
  • A letter
  • A digit
  • $
  • _
Gosu also supports Unicode characters above the extended ASCII range. For example:
  • var русский_язык = 1.0
  • var Español = 2.0
  • var 日本語_$ = 3.0
  • print(русскийязык * Español * 日本語$)