TeaScript Syntax
WIP documentation of TeaScript. Feel free to add any information necessary below.
Variables
To make a variable, open the variable menu by going to view -> Variable or ctrl+I. Then click 'Add' to make a variable. https://cdn.discordapp.com/attachments/273281168130965504/315971257713557504/unknown.png
Types of variables:
- Local Variable
- v(name) or val(name)
- str(name)
- Local Array
???
- Global Variable
- gv(name) or gval(name)
- gstr(name)
Expressions
Mathmatical Symbols
| Symbol | Name | Example |
|---|---|---|
| (+) | Addition | 3+2=5 |
| (-) | Subtraction | 3-2=1 |
| * | Multiplication | 3*2=6 |
| / | Division | 3/2=1.5 |
| \ | Division with no remainder | 3\2=1 |
| ^ | Power | 3^2=9 |
| & | Concatenation | 3&2=32 |
| () | Parentheses | (3+2)*6=30 |
| mod | Modulus | 3 mod 2 = 1 |
Functions
These are the mathmatical function provided.
Parameters with #param mean that the parameter is a double.
Parameters with "param" mean that the parameter is a string.
| Functions | ||
|---|---|---|
| Name and Parameters | Return Type | Description and Example |
| abs(#num) | Double | Returns the absolute value of a number
abs(-3) 'returns 3
|
| exp(#num) | Double | Returns the number to the power of the e constant
exp(5) 'returns e^5
|
| log(#num) | Double | Returns the log of the number with a base of e
log(e) 'returns 1
|
| sgn(#num) | Double | Returns the sign of the number (1, -1, or 0)
sgn(10) 'returns 1
sgn(0) 'returns 0
|
| int(#num) | Double | Returns the number rounded up. Similar to the common ceiling function
int(2.1) 'returns 3
|
| fix(#num) | Double | Returns the number rounded down. Similar to the common floor function
int(2.9) 'returns 2
|
| sqr(#num) | Double | Returns the square root of a number
sqr(9) 'returns 3
|
| sin(#num) | Double | Returns the sine of the number. Uses radians
sin(pi) 'returns 0
|
| cos(#num) | Double | Returns the cosine of the number. Uses radians
cos(pi) 'returns 1
|
| tan(#num) | Double | Returns the tangent of the number Uses radians
cos(pi/4) 'returns 1
|
| atn(#num) | Double | Returns the inverse tangent of the number. Uses radians
atn(1) 'returns pi/4
|
| getangle(#x, #y) | Double | Returns the angle (from 0 to 1) formed between the triangle. Similar to the common atan2 function.
getangle(1, 0) 'returns 0
getangle(1, 1) 'returns .125
getangle(0, 1) 'returns .25
getangle(-1, 0) 'returns 0.5
getangle(0, -1) 'returns 0.75
|
| rgba(#red, #green, #blue, #alpha) | Double | Returns an SMBX color value. Parameters must be between 0 and 255
rgba(255, 255, 255, 255) 'returns -1
|
| round(#num, #decimal_place) | Double | Returns the number rounded
round(1.3456, 2) 'returns 1.35
|
| len("txt") | Double | Returns the length of the text
len("ABC") 'returns 3
|
| left("txt", #len) | String | Returns the text cropped starting with the length provided. The crop begins from the start |
| right("txt", #len) | String | Returns the text cropped starting with the length provided. The crop finished with the end |
| mid("txt", #len) | String | Returns the text cropped starting with the length provided. The crop begins with the number provided. |
| replace("txt", "search", "replacement", #start, #count, #case_insensitive) | String | Replaces a part of the text with a new one.
|
| asc("character") | Double | Returns the ANSI code. It will use the first character if more than one is passed |
| chr(#code) | String | Returns a string using the ANSI code. Accepts 0-255 |
| ascw("character") | Double | Returns the unicode code. It will use the first character if more than one is passed |
| chrw(#code) | String | Returns a string using the unicode code. Accepts 0-65535 |
| cstr(#num) | String | Converts the number to a string |
| cdbl("txt") | Double | Converts the string into a number |
| instr(#start, "string1", "string2") | Double | To return the point of the first appearance of a given string in another string.
|
Special numbers
- pi = 3.141592654
- e = 2.71828182
- rnd = A random value between 0 and 1.
Comparing and Logical Operators
| Symbol | Name | Example |
|---|---|---|
| Equal | = | 5 = 4 + 1 => (1)true |
| Not Equal | <> | 5 <> 3 => (1)true |
| Greater than | > | 5 > 3 => (1)true |
| Less than | < | 4 < 5 => (1)true |
| Greater than or equal to | >= | 5 >= 5 => (1)true |
| Less than or equal to | <= | 3 <= 3 => (1)true |
The logical operators in Teascript are: not, and, or, xor, eqv, and imp.
| P | not P |
|---|---|
| 0 | 1 |
| 1 | 0 |
| P | Q | P and Q | P or Q | P xor Q | P eqv Q | P imp Q | |
|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 | |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | |
| 1 | 0 | 0 | 1 | 1 | 0 | 0 | |
| 1 | 1 | 1 | 1 | 0 | 1 | 1 |
Control Flow
If statements
if [conditon] then
'statement that should run if the first condition is true
elseif [condition] then
'statement that should run if the other condition is true
else
'statement that should run if all the other conditions are false
end if
Select Case
Select Case lets you easily organize the control flow by a value.
select case v(var)
case 0 to 1
'Script that should pass if v(var)'s value is between 0 and 1.
case 2
'Script that should pass if v(var)'s value is exactly 2.
case else
'Script that should pass if v(var)'s value does not match any of the other conditions.
end select
For Loop
Do Loop
There are three different versions of do loops: While loops, Until Loops, and Pure Loops.
'Pure loop:
do
'this loop will run infinitely until it hits an "exit do" statement
loop
'While Loop:
do while [condition]
'this loop will run as long as the condition returns true
loop while [condition]
'Until Loop:
do until [condition]
'this loop will run until the condition returns true
loop until [condition]
With while and until loops, you may choose where to place the 'while' or 'until' keyword. There can only be one of either keyword in the entire loop.
With Statements
Goto
Using goto it will force the script to jump to the specified line using a label.
Example:
[statements]
goto Example
When the script reached "goto Example" it will jump to "Example" and execute the script below it. The labels used with goto statements must: have names that do not contain characters that do not follow variable name rules and there must not be two labels with the same name.
GoSub
Script
Using the script keyword, it allows you to make function in Teascript. Example:
script name(myParam as double, return double)
return param(myParam) + 1
end script