Functions (TeaScript)
The following page contains all TeaScript functions. Click here to return to the Category: Teascript page.
AudioSet
This function allows you to play sound effects, or play/stop music. This function can be called through both level scripts and global/map scripts.
To load a sound effect:
call AudioSet(1, ID, Advanced, Filepath)
Parameters | Description |
---|---|
ID | Sound effect ID can range from 0 to 1024.
IDs from 1 to 92 replace default sound effects. |
Advanced | Whether only one 'copy' of this sound effect can be played in the same time. |
Filepath | The filename of the sound file. The sound file must be in the world map folder. |
To play a sound effect:
call AudioSet(2, ID, Loop, "")
Parameters | Description | |
---|---|---|
ID | Sound effect ID can range from 0 to 1024.
| |
Loop | Whether the sound loops or not. |
To stop a sound effect:
call AudioSet(3, ID, 0, "")
Parameters | Description |
---|---|
ID | The ID of the sound effect. Can be between 0-1024. |
To Change a specific sound volume:
call AudioSet(5, ID, Volume, "")
Parameters | Description |
---|---|
ID | The ID of the sound effect. Can be between 0-1024 |
Volume | Can be between 0-100. |
To play music:
call AudioSet(11, FadeIn, 0, Filepath)
Parameters | Description |
---|---|
FadeIn | The duration of the fade-in effect in milliseconds. |
FilePath | The filename of the music file. The sound file must be in the world map folder. |
To stop music:
call AudioSet(12, FadeOut, 0, "")
Parameters | Description |
---|---|
FadeOut | The duration of the fade-out effect in milliseconds. |
BErase
Erases a bitmap, iterator, or text object when called.
Note: If you only want to temporarily hide the object, modify the object's hide property instead of using this function.
call BErase(type, id)
Parameters | Description |
---|---|
type | The object type to be erased.
0 = Iterator 1 = Text 2 = Bitmap 3 = Block |
ID | The ID of the object to be destroyed. The function will do nothing if the object is not found. |
BmpCreate
This function can create a highly customizable bitmap object, but needs an NPC as the bitmap's source.
Use this function with caution! Performance issues may occur if too many bitmaps are created at once, and the game may crash if sx, sy, sw, and/or sh, are invalid.
call bmpcreate(id, picid, useScreenCoords, isVisible, sx, sy, sw, sh, destx, desty, stretchx, stretchy, centerx, centery, angle, color)
Parameters | Description |
---|---|
ID | The ID slot to be used for the bitmap being created. If another bitmap is reserved for the ID specified, nothing will happen. |
picID | The ID of the NPC to use as the bitmap source. |
useScreenCoords | Determines how the bitmap will be oriented.
0 = Bitmap's coordinates will be relevant to the level's coordinate system. 1 = Bitmap's coordinates will be relevant to the top left corner of the screen, and will move accordingly with the screen. |
isVisible | If set to 0, the bitmap will be hidden upon creation. If set to 1, it will be visible. |
sx | The x coordinate of the top-left point of the sprite in the bitmap's source file. |
sy | The y coordinate of the top-left point of the sprite in the bitmap's source file. |
sw | The width of the cropped bitmap. |
sh | The height of the cropped bitmap. |
destx | The x coordinate of where the bitmap will be drawn. |
desty | The y coordinate of where the bitmap will be drawn. |
stretchx | The bitmap's x-axis stretch ratio. Set to 1 for no stretching. |
stretchy | The bitmap's y-axis stretch ratio. Set to 1 for no stretching. |
centerx | The x coordinate of the bitmap's hotspot/centerpoint used for stretching and rotation. |
centery | The y coordinate of the bitmap's hotspot/centerpoint used for stretching and rotation. |
angle | The rotation angle of the bitmap in degrees. |
color | The forecolor of the object. Set to -1 if you don't want to use forecolor. |
BSet
This function is used to modify object configuration flags. The usage of this function is so complex it needs its own page, BSet (TeaScript).
EXEScript
This function is used to execute a script. When this function is called, the given script will immediately be executed and the original script will be halted until the execution of the given script completes. This can be used to call world map/global scripts. This function can be called through both level scripts and global/map scripts.
call EXEScript(ScriptName)
Parameters | Description |
---|---|
ScriptName | The script that should be executed. |
Debug
This function will output a string to the debug box. It will only work in the editor, and will not do anything in game mode. It is recommended to delete these functions after debugging for better performance. You can find the debug box by opening the debug menu and double clicking the object count.
call Debug(String)
Parameters | Description |
---|---|
String | The string that should be outputted. |
FXCreate
This function is used to create an effect.
call FXCreate(ID, X, Y, Xsp, Ysp, Frames, AnimationSpeed, Const, Gravity, Advanced)
Parameters | Description |
---|---|
ID | The effect-ID of the effect to create. |
X | The X-scene coordinate where the effect will be created. |
Y | The Y-scene coordinate where the effect will be created. |
Xsp | The X-speed of the effect. |
Ysp | The Y-speed of the effect. |
Frames | The number of frames the effect should last. |
AnimationSpeed | The number of frames each animation frame will last. |
Const | The sprite set to use (i.e. setting value to 1 for effect-77 uses Luigi's fireball colors) |
Gravity | Should the effect be affected by gravity?
|
Advanced | Advanced value for the effect. Used in effect-77 (fireball's particles) and effect-79 (score). |
HUDSet
This function allows you to draw your own HUD. The function serves different purposes with the first parameter. Remember the HUD must must be initialized before adding any text or bitmaps.
To erase previous HUD data and initialize the HUD system:
call HUDSet("initialize", 0, 0, 0, 0, 0, 0, 0, 0, 0)
To disable the custom HUD system and erase all the previous custom HUD data.
call HUDSet("destroy", 0, 0, 0, 0, 0, 0, 0, 0, 0)
To add a bitmap to the HUD:
call HUDSet("bitmap", ID, XSource, YSource, Width, Heigth, X, Y, Advanced, Color)
The image source must be in a file called 'scflash.png'.
Parameters | Description |
---|---|
ID | The ID used to identify the HUD bitmap (shares ID with non-HUD bitmaps). |
XSource | The X-position of the top-left point of the object in scflash.png. |
YSource | The Y-position of the top-left point of the object in scflash.png. |
Width | The width of the cropped bitmap. |
Height | The height of the cropped bitmap. |
X | The X-scene coordinate where the bitmap will be created. |
Y | The Y-scene coordinate where the bitmap will be created. |
Advanced | The advanced settings of the HUD bitmap.
|
Color | A certain color. The default value is -1 and type 0 to make the bitmap completely transparent. |
To add text to the HUD:
call HUDSet("text", ID, X, Y, StartASCII, EndASCII, RowASCII, NPCID, Color, -1)
Parameters | Description |
---|---|
ID | The ID of the text. The function will create a new text if the ID is unused, otherwise it will overwrite the existing text. |
X | The x position of the text. |
Y | The y position of the text. |
StartASCII | The starting character code of the font. |
EndASCII | The last character code of the font. |
RowASCII | The number of characters in a row of the font image. |
NPCID | The ID of the NPC ID that contains the font used. |
Color | A certain color. The default value is -1 and type 0 to make the text completely transparent. |
ItrCreate
Creates an iterator. This iterator can let you cycle between objects in a given rectangular area.
dim ItrID as integer = itrCreate(type, ID, x, y, w, h)
Parameters | Description |
---|---|
type |
|
ID | The ID filter of the iterator. Set this to 0 to disable ID filtering.
If If For all other types, this value stands for the image-file ID (E.g: use |
X
|
Stands for the x-position of the top left corner of the iterator. The iterator only will iterate through objects within the defined rectangular region |
Y
|
Stands for the y-position of the top left corner of the of the iterator. |
W
|
Stands for the width of the iterator. |
H
|
Stands for the height of the iterator. |
ItrNext
Continues through an iterator that was created prior. Returns the index (permanent ID) of the found object. Use this index in classes, for example NPC(index)
or Block(index)
. If the iterator is finished, this function returns 0.
You must destroy the iterator with BErase(0, ITERATOR_ID) or else the iterators won't work anymore until you restart the game.
If the game does not crash but iterators stop working, it means you have an iterator leak because you forgot to berase an iterator after its usage (it occurs when more than 128 iterators exists simultaneously)
dim index as integer = itrNext(ID)
' Assuming the iterator in a block iterator
with block(index)
call Debug(.id) 'You can apply code to every object in the iterator like this!
end with
' How to cycle through all objects
dim iD as integer
dim iN as integer
iD = itrCreate(type, ID, x, y, w, h)
do
iN = itrNext(iD)
if iN = 0 then exit do
' Here you can execute code to every object
loop
call BErase(0, iD) ' Dont forget to BErase, its very important
Parameters | Description |
---|---|
ID | The ID of the iterator. This is given to you via ItrCreate
|
KeyPress
This function returns the user input data. This can be used to check a keyboard key, mouse cursor, and player keys being held.
if KeyPress(ID) then
Example of using 'keypress' to detect a single key press, which triggers only on the initial key press and resets when the player releases the key:
dim upKey as integer ' Stores the key state of the 'Up' key
do
if upKey = 0 and keypress(-14) then
call showmsg("Up pressed!")
end
upKey = keypress(-14)
call sleep(1)
loop
Parameters | Description |
---|---|
ID | The ID of the input. |
LMove
This function is used to move layers.
call LMove(LayerName, Xsp, Ysp, Type)
Parameters | Description |
---|---|
LayerName | The name of the layer that you want to move. |
Xsp | The X-distance speed the layer should move. (Xsp is difference between original and destination (i.e. value is 32, layer is moved 32 pixels from original coordinate) coordinates if shift movement was used) |
Ysp | The Y-distance speed the layer should move. (Ysp is difference between original and destination (i.e. value is 32, layer is moved 32 pixels from original coordinate) coordinates if shift movement was used) |
Type | The type of movement that the layer should use.
|
LSet
This function is used to change the visibility of a layer. This function can be called through both level scripts and global/map scripts.
To Show/Hide/Toggle a layer:
call LSet(LayerName, Type, Smoke)
Parameters | Description |
---|---|
LayerName | The name of the layer that you want to change. |
Type | The type of layer visibility.
|
Smoke | Should there be smoke?
|
To change the alpha value of a layer:
call LSet(LayerName, 38, AlphaValue)
Parameters | Description |
---|---|
LayerName | The name of the layer that you want to change. |
Alpha Value | The alpha value of the layer. This value must be between 0-255. |
LSpin
This function is used to rotate layers. This function only affect NPCs and Blocks. This function can be called through both level scripts and global/map scripts.
call LSpin(LayerName, Xcenter, Ycenter, Speed)
Parameters | Description |
---|---|
LayerName | The name of the layer that you want to spin. |
Xcenter | The X-scene coordinate of the center of the circle. |
Ycenter | The Y-scene coordinate of the center of the circle. |
Speed | The spin speed. Positive values spin counterclockwise and negative values spin clockwise. |
NCreate
This function is used to spawn an NPC. The function returns the permanent id of the spawned NPC.
call NCreate(ID, X, Y, Xsp, Ysp, Advset, CreationData)
'If you want the permanent id of the spawned NPC, do:
dim NPCpermID as integer = NCreate(ID, X, Y, Xsp, Ysp, Advset, CreationData)
Note that the spawned NPC becomes active until the next frame.
Parameters | Description |
---|---|
ID | The NPC-ID that should be spawned. |
X | The X-coordinate of the spawned NPC. |
Y | The Y-coordinate of the spawned NPC. |
Xsp | The X-Speed of the spawned NPC. |
Ysp | The Y-Speed of the spawned NPC. |
Advset | The "advset" field of the spawned NPC. |
CreationData | The way the NPC will be created:
|
NCreateGroup
This function can create a group of NPCs when called. It works similarly to the NPC's HoldGenerator.
call ncreategroup(ID, X, Y, XOffset, YOffset, NPCcount, Angle, Range, Speed, Advanced)
Parameters | Description |
---|---|
ID | The ID of the NPC to be created. |
X | The X position of the spawn point. |
Y | The Y position of the spawn point. |
Xoffset | "The X-Offset of the generator this npc attached." |
Yoffset | "The Y-Offset of the generator this npc attached." |
NPCcount | The number of NPCs to be created. |
Angle | The angle that the NPC will be created from. |
Range | Distance between the group of NPCs. |
Speed | Speed that the NPC will have, when created. |
Advanced | The advanced value of each NPC. |
NKill
This function will destroy an NPC when called if all parameters are met.
call NKill(index, rx, ry, rw, rh, id, effect, score)
Parameters | Description |
---|---|
index | How the NPC is to be destroyed. If the value is greater than 0, the value will stand for the NPC's ID to be used.
0 = The function will delete the specified NPC. -1 = The function will delete all NPCs touching a rectangular box. -2 = The function will delete all NPCs that are completely enclosed in a rectangular box. |
rx | The x-position of the rectangular box. If "index" is 0, use 0 here. |
ry | The y-position of the rectangular box. If "index" is 0, use 0 here. |
rw | The width of the rectangular box. If "index" is 0, use 0 here. |
rh | The height of the rectangular box. If "index" is 0, use 0 here. |
id | If "index" is -1 or -2, this parameter will stand for the ID of the NPCs to delete. Set this to 0 to delete all NPCs. If "index" is 0, use 0 here. |
effect | Determines whether the NPC's death effect is used upon being destroyed. Set to 0 to disable effects, set to any other value to enable effects. |
score | Determines whether the NPC's defined score is rewarded to the player. Set to 0 to disable scoring, set to any other value to enable scoring. |
PlayNote
This function is used to play midi notes.
call PlayNote(Command)
The first time this command is used, the game stutters for a few frames. It is recommended to use call playNote(139)
at the beginning of the level to avoid any stutters.
Parameters | Description |
---|---|
Command | The command can be:
Patch = ID of the instrument (0-127) Volume = The volume of the note (0-100) Flip = The pitch of the note (0-255) Channel = The channel of the note (0-15) Default:0 |
Here is a simplified way to play a note. Use this chart to identify your instruments.
dim instrument as integer = 55 ' You must subtract 1 to the ID found in the wiki (For example, in the wiki orchestra hit is 56, but here you must use 55)
dim volume as integer = 100
dim pitch as integer = 50
dim channel as integer = 1 ' MUST NOT BE 9
call playNote(instrument*256 + 192 + channel) ' This switches the instrument
call playNote(volume*65536 + pitch*256 + 144 + channel) ' This starts the note. NOTE: the note does not automatically stop. You must stop it manually.
call playNote(128 + channel) ' This stops the note.
Here is a simplified way to play a percussion note. Use this chart to identify your instruments.
dim instrument as integer = 56 ' This is the ID as found in the wiki page. No need to modify the ID
dim volume as integer = 100
call playNote(volume*65536 + instrument *256 + 144 + channel) ' NOTE: You cannot stop the note manually, this one stops automatically after its finished playing.
Redim
This Function is used to initialize a local array.
Call Redim(type,name,size)
Parameters | Description |
---|---|
Type | 0 = All Memory allocated to the array will be cleared. (Default)
1 = Resize array. |
Name | Name of the local array to be started. |
Size | Size of local array |
ScriptID
Returns the Script ID.
val(a) = scriptid(name)
Parameters | Description |
---|---|
Name | The script that should return your ID. |
SCSet
This function allows you to change or check the starcoin acquisition status.
To get a starcoin:
call SCSet(levelname, scID, 0)
Parameters | Description |
---|---|
levelname | The filename of the level. |
scID | The starcoin ID. The value is the same as Star Coin IDN in the advanced tab. |
To check a starcoin acquisition status:
value = SCSet(levelname, scID, 1)
Parameters | Description |
---|---|
levelname | The filename of the level. |
scID | The starcoin ID. The value is the same as Star Coin IDN in the advanced tab. |
To clear a starcoin status:
call SCSet(levelname, scID, 4)
Parameters | Description |
---|---|
levelname | The filename of the level. |
scID | The starcoin ID. The value is the same as Star Coin IDN in the advanced tab. |
To clear all starcoins status in a certain level:
call SCSet(levelname, 0, 5)
Parameters | Description |
---|---|
levelname | The filename of the level. |
ShowMsg
This function shows a message using a message box. RGB, quake, break, and alpha message formats are supported. This function can be called through both level scripts and global/map scripts.
call ShowMsg(Message)
' How to use text markup:
' == Color ==
call showMsg("\cHEXtext") ' \cHEX changes the color of all the text afterward with HEX being the color wanted. \cFF0000 will make the text red. You can have multiple colors per message like this:
call showMsg("\cFF0000RED! \c00FF00 GREEN! \c0000FF Blue!")
' == Fade==
call showMsg("\alphaTEXT") '\alpha will make the all the text afterward fade in. You can make only a part of the text fade in by ending it with another '\alpha'. Try this example to see how it works:
call showMsg("\alphaHello, I am fading!\alphaHello, I do not fade!\alphaI will fade as a second group!")
' == Break ==
call showMsg("TEXT\nTEXT") '\n it will break the line and the following text will continue to the next line like this:
call showMsg("Line 1\nLine 2\nLine 3")
' == Quake ==
call showMag("\quakeTEXT") '\quake will make all the text afterwards a "shake" effect. You can make only a group of text shake by ending it with another '\quake' like this:
call showMsg("\quakeHello, I am shaking\quakeI am not shaking")
' How to concatenate strings:
dim player as string = "Mario"
call showmsg("Hey there " & player & ", I hope you're having a fantastic day!)
Parameters | Description |
---|---|
Message | The message that will be shown. It must be a string. |
Sleep
This function is used to pause the script for a number of frames.
Sleep only be used in scripts called through an event.
call sleep(Delay)
Parameters | Description |
---|---|
Delay | The number of frames the script should be paused. |
SpEvent
This function is used to trigger special events.
call SpEvent(ID)
Parameters | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ID | The ID of the special event. Can be seen by right clicking the special event menu.
|
SysShowInput
Will show a message box that has a text box. This textbox can be read and stored
call SysShowInput(Message, Title)
'If you want the written text, do:
dim input as string = SysShowInput(Message, Title)
Parameters | Description |
---|---|
Message | The message that is shown in the message. Must be a string |
Title | The title that is shown in the message. Must be a string |
SysShowMsg
Will show a message box with default options.
call SysShowMsg(Message, Type, Title)
'If you want the selected option, do:
dim optionID as integer = SysShowMsg(Message, Type, Title)
Parameters | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Message | The message that is shown in the message. Must be a string | ||||||||||||||||||||||||||||||
Type | The ID of the message box.
This is the ID returned
| ||||||||||||||||||||||||||||||
Title | The title that is shown in the message |
TClear
This function clears and deletes timers, such as timers done for events.
call TClear(Type, EventName)
Parameters | Description |
---|---|
Type |
|
EventName | If type is 0, then set this to the name of the event to be cleared as a string. Otherwise, set this to 0. |
TCreate
This function is used to call an event/create an event timer. This function can be called through both level scripts and global/map scripts.
call TCreate(EventName, Delay)
Parameters | Description |
---|---|
EventName | The event that should be called as a string. |
Delay | The number of frames until the event is called. |
TCreateEx
This function is used to execute a script after the set delay and pass parameters to the said script.
call TCreateEx(ScriptName, Delay, Param1, Param2, Param3)
Parameters | Description |
---|---|
ScriptName | The script that should be executed. |
Delay | The number of frames until the script is executed. |
Param1 | The value that should be passed to Sysval(Param1). |
Param2 | The value that should be passed to Sysval(Param2). |
Param3 | The value that should be passed to Sysval(Param3). |
TxtCreate
This function is used to create a text object.
call TxtCreate(id, x, y, sasc, easc, cdata, lnum, fontid, flag, text)
Parameters | Description |
---|---|
id | The unique identifier of the text. |
x | x-position of the text. |
y | y-position of the text. |
sasc | the beginning ASCII code of the NPC image font. |
easc | the last ASCII code of the NPC image font. |
cdata | reserved.Type 0. |
lnum | the number of characters of a single row in the NPC image file. |
fontid | ID of the NPC used as the font.Use the numbers in the NPC image filename as the ID. |
flag | 0: coordinates will be oriented to the scene. 1: coordinates will be oriented to the screen. |
text | The text shown. |