TeaScript Basic Tutorial

Description: Internal scripting system of SMBX-38A Engine based on the simple VB-like language
Moderators: Lx Xzit, Yoshi021, 5438A38A, Moderators, Semi-moderatos

Catskart M
Topic author, Count
Count
Avatar
Catskart M
Topic author, Count
Count
Age: 20
Reputation: 140
Posts: 258
Joined: 29 Nov 2015
Location: France

Post #1by Catskart » 9 Jan 2017, 23:44

TeaScript Basic Tutorial



This tutorial is originally in French, it was translated by Marioisfan12, and I arranged some things.

Introduction :

Hello everyone!
So, for those of you that don't know it a script system has been added since the 1.4.1 version of SMBX.

The language used is Teascript, created by 5438A38A, it is very similar to Visual Basic.
The interests of this system is exceed the limits of the level editor, for example it's possible to :
- Create a custom HUD.
- Customize the NPCs more. (Projectiles, speed)
- Make some minigames. (Like Tetris)


How it works :

To open the script editor, you have to click the "View" button near to "Test Level", you'll see this:

Image

Click "Add" to add a script.
Click "Delete" to delete a script.
Type in "Script List" to change the name of your script.


Click on "Add" and this comment will appear in the right window :

Code: Select all

'Script No.1 Name:New Script


Yeah, I say comment because all the lines which start with ' are comments, it means some texts that don't have some influence with the script.
If you see a ' before a line in a code, then you don't have to copy this line

Activation of the script :

To activate a script, you need an event that will launch the script. If you feel lost in the new interface of the Events' Window, here are the steps :

Image

(The scripts can be activate with the liquids and the warps.)

Two types of alues :

If you read the help file, you should see sometimes the words "double" or "string".

The "double" value is a value with numbers. (4,550,42,96,...)
The "string" value is a value with texts. ("a","hey","ok",...) And it is always written with citations.

A little example ?

To explain what I'm saying, then, this time we'll create an help block of SMW that will say a little comment. (maybe to help us with the game)

Let's create a script, you can choose the name, I'll call it, "Mon script".

Image

The block will tell us how many coins the player has got.
The command that will make the message pop up is:

Code: Select all

Call ShowMsg(String)


Replace "String" with the message that will be shown.

You have at first to place a first string after ShowMsg.

Code: Select all

Call ShowMsg("The total of coins is")


We place this message before, because later we'll type a double variable, but like ShowMsg works only with string values, then we'll use the CStr, that converts doubles values in strings.

Code: Select all

Call ShowMsg("The total of coins is" & CStr(sysval(CoinCount)))

Obviously, we don't forget the "&" to connect them.

Then later, we'll put another string that will be the end of the sentence.

Code: Select all

Call ShowMsg("The total of coins is" & CStr(sysval(CoinCount)) & ".")



Then we'll make possible that the help block leaves an opinion about the number of the coins that we have, and for that, we'll use the conditions!

Normally, if you have got Visual Basic codes, TeaScript works similarly.

But first we have to type what is the condition, so, we'll say if the player has got more than 50 coins.

Code: Select all

If sysval(CoinCount) > 50 then
'sysval(CoinCount) is a variable about the coins.
'Don't forget to type the "then". If you forget it, it will be an error

else
'Otherwise

end if
'End of the condition.


Then, use the command "ShowMsg", with a string.

Code: Select all

If sysval(CoinCount) > 50 then
'sysval(CoinCount) is a variable about the coins.
'Don't forget to type the "then". If you forget it, it will be an error.
Call ShowMsg("Nice, you are rich!")
else
'Otherwise
Call ShowMsg("OUAHAHAH!")
end if
'End of the condition.


Normally you should see this script:

Image
(This is the same script in french.)

Voilà, now we'll create an event that will launch this script.
Let's create an Event, and let's go to "Others" in the "Functions". Then Select the script (In this case, Mon Script)
If your event is here only to launch a script, you can add [SCRIPT] to your event's name !

Image

Warning, SMBX could clear the script (not in the script editor, in EVENTS) if you modify the section "Others".

Then you have to put the block that will active the script, and the game is done! Enjoy!

Image

What will happen if you set an error in a script ?

SMBX will say what's the error and where it happens, and the script won't be launched.

Return to “TeaScript”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest