TeaScript Syntax

User Variables
User variables can be access in the variable menu or by pressing ctrl+i. All of these variables must be created using this interface.

Doubles & Strings
By clicking the  button in the variable interface you create a user variable.

You may also select if the variable is a local or global. Local  can only exist in a single level and the value is reset every time the level begins. Global variables save the value per level and remembers the value even after quitting the game.

Variable Naming Standard


 * Names are not case sensitive.
 * Names must not contain spaces.
 * Names must be made using a combination of letters and numbers only.
 * Names must start with a letter

work in an unusual way compared to other scripting languages. A  has two sides, a   and a. There are different methods to access each side Note how a  simultaneously can hold a   and a.

Arrays
By clicking  while holding shift in the variable interface you create a. Currently,  can only contain   values. must first be initialized using the redim  before usage.

Dim Variables
are a different way of creating and interacting with variables compared to user variables. A  can only have a single type of data that must be defined on creation. Variable naming standards are the same as, except you may not use the same name of other existing   and. If a  is initialized without a value, it defaults to 0 or "" depending on the type. Here is a list of all the different types of dim variables. While TeaScript offers all these types, it is recommended to stick with integer,  , and.

Expressions
An expression is a line of code that evaluates to an answer. Something as simple as  is an expression. Teascript offers different tools to create diverse expressions that suit what you specifically need.

Comparing Operators
Note that all  require both sides use the same data type. You can compare numbers with other numbers and strings with other strings, but you cannot compare numbers with strings.

Logical Operators
only work on numbers. They are commonly used with -1 and 0 to represent true and false respectively. Other numbers can be used but it may yield different patterns.

Special Values
These special values behave like numbers.

Built-in Functions
are powerful tools that allow you to simplify and expand the flexibility of your scripts. To access a, you write the function name and in parenthesis write the parameters separated by commas. You can put  inside an   just as it were a regular number or string.

For a list of  created by the community check here. These are the the mathematical  provided in TeaScript.

Parameters can be numbers, strings, and arrays.

Control Flow
When a  is run in TeaScript it will start reading the   from top to bottom, left to right. It will read and execute the code in that order. the following is a list of ways to customize and manipulate what code gets executed in your.

Declarations
A  is when you set a value to a variable. This applies to,  , and other values.

Conditions
represent true and false. In Teascript, -1 and 0 represents true and false. Any number that is not 0 may also represent true, but use -1 and 0 for consistency reasons.

If Statements
The  is a basic but useful statement. It has one parameter being a. When TeaScript reads an  it will check each   from top to bottom until it reaches a   that is true. When it reaches a  that is true, it will execute the   inside and continue the code after the entire. This means that  written on the top will have priority over those   in the bottom.

The  is special since it does not require any. An  must be written in the bottom after all other   statements (if there are any). The code inside the  will only run if every other   in the    and   statements evaluated to false.

Select Case Statements
lets you easily organize the control flow based on a value. It has one parameter being a value.

at its core is similar to various  and behaves similarly to the common "switch" statement in other languages. It will read the value that is passed and executes the first code in which the value matches. It will read the cases from top to bottom giving priority to cases at the top.

The  keyword can be used when checking for a case.


 * Numbers Will be true if the value is between (inclusive) the two numbers provided.
 * Strings Unknown pattern

The  keyword can be used to make comparisons to the value. It can be used with the   or   logical operators.

You can use commas to check for multiple cases at once. The commas behave similarly to an  logical operator. The case will go through if it matches with any of the cases.

With Statements
are useful to read or write on multiple properties of an object. An object can be for example an NPC, Block, or BGO. Check the classes section for more information on SMBX Objects. You can acess all of the properties by typing a  followed by the property name.

Goto
Using  will force the script to jump to a specific line to a specific label. The label name must be followed by. does not work inside.

GoSub
Using  will force the script to jump to a specific line to a specific label. Teascript will remember where the jump happened and can be returned by using  .The label name must be followed by. does not work inside.

Loops
A loop allows you to run a piece of code multiple times. Teascript is very flexible in the type of loops you can create.

It is important to note that you should avoid an infinite loop. Creating an infinite loop will freeze the game. Make sure to either have a  function (if the script was called by an event) or an.

Pure Loops
A  is a very simple and basic form of a loop. It will run indefinitely.

While Loops
A  will continue the loop while the   is. You can set up a  in 2 different ways. The difference is by when the loop checks its condition. If you place the  at the bottom, you guarantee then code will be run at least once.

Until Loops
An  will continue the loop until the   is. You can set up an  in 2 different ways. The difference is by when the loop checks its condition. If you place the  at the bottom, you guarantee then code will be run at least once.

For Loops
A  will run for a set amount of times. You declare a variable then will count the current iteration it is on. A  has 3 parameters and they are: ,  , and.

A  will continue to loop as long as your counter is less or equal to the. The  will also stop if your counter is less than your. For every iteration, your counter will increase by the.

Exit
An exit statement will terminate a loop of a script prematurely.

Scripts
Teascript allows you to create  function inside your scripts. This allows you to simplify your code and build tools to expand your script in a more organized manner. There are two types of  that both work very similarly.

When setting up a  or , all   and   names must follow variable naming standards with one exception. Script names must not contain numbers anywhere.

Function
A  allows you to create your own custom functions that behave similarly to the   shown above. You can add your own  to simplify code or add your very own mathematical functions. You can have as many  as you want. You must define the type of data and the return type as shown below. If no  is found, then by default it will return 0 or "" depending on the return type. A  must be defined at the bottom of the script.

Procedure
A  are similar to   except they do not have a return value. Use custom procedures to create instructions that you want to repeat together. You can have as many  as you want. You must define the type of data as shown below. A  must be defined at the bottom of the script.

Oddities and Quirks
The following is a list of oddities that you may experience when using TeaScript

Dim Variables in If Statements

If you initialize a dim variable inside an if statement, it will have a buggy effect. This is a bug in Teascript's side.

Procedure-Function Combo

When  a   you can ignore the return value. This serves no practical purposes. Negatives to a Non-Integer Power

is equivalent to. Therefore  results in a complex number with a imaginary component. Teascript does not offer complex numbers in its data types. Writing Double Quotation Marks Since double quotation marks are reserved for defining string, you must use chr or chrW to write a double quotation mark inside a string.

> THESE PROBLEMS ARE FIXED in 1.4.5 <

Writing Decimal Numbers When writing decimal number, you must include a number before the decimal point.

Writing negative numbers When writing a negative number, make sure there are no other symbols beforehand (except parenthesis).