* What Teascript has similar with Visual Basic or some language.
It is the smbx38a scripting system with syntax similar to that of VB6.
Declaration of variables:
- Like the one in VB6, you can declare them by typing:
Dim name_var As variable_type
It has the types: byte, string, single, integer, double, long, but not boolean or the const keyword. This way of having variables is available since 1.4.5.
In VB6 there is an alternative way to declare variables that teascript doesn't:
- Dim var1$ ‘String
Dim var2% ‘Integer
Dim var3& ‘Long
Dim var4! ‘Single
Dim var5# ‘Double
Table of variables:
- All scripts at the level can access these variables with the function val for numbers and str for strings: they are called local variables.
If you press the Add button + shift key you will add an array of one dimension, it is as if you wrote:
Dim name_array() as double (you can't declare arrays)
It has no number of elements so you have to use the redim function which has 3 parameters:
First parameter is if you want to preserve the elements.
Second parameter is the name of the array.
Third parameter is the number of elements.
To read and write you use the function array:
There are no matrices.
String variables cannot be seen in the variable table.
Everything is like VB6, though:
Selective structures: [IF, ELSE, ELSEIF, SELECT CASE]
- * You cannot write an addition after the then:
If condition then var+=1
Works with: If condition then var=var+1
* In 1.4.5 it is not necessary to write 'then', if everything is in one line if necessary.
* Logical operators: AND, OR, XOR EQV and IMP
* Bitwise scrolling operations: In 1.4.5 path 28 << and >> were added
* hexadecimal literal: &H1B38AF
* octal literal: &o1510
* binary literal: &b101011 (Something added in VB NET 2015/2017)
Repetitive structures: [DO, LOOP, WHILE, UNTIL, FOR NEXT]
- * Up to 1.4.5 it reaches 100%, in previous versions when using an EXIT DO and if right after there is an ELSE there was an error, you had to put the EXIT DO in the last nested condition for it to work.
* Since 1.4.4 there is a function to use it with DO LOOP called Itrcreate and Itrnext to iterate the IDs of the objects quickly, after finishing the iterator you must destroy the itrcreate with berase.
* GOTO and GOSUB should not be used inside a WITH block
We have the following functions to support this:
- Script name_funcion (parameter1 as type1, parameter2 as type2,…, return type)
It is the normal function except that the return value is a parameter, if it does not have a return value it is a Sub like VB6, to return and finish we use return (if it is in the parameters), it is not like VB6 that you have to match the name from your function to the variable you want to return.
In versions prior to 1.4.5 to access any parameter of the function you had to use Param (for numbers) and Strparam (for strings).
The parameters of the SCRIPT function are by value: ByVal in VB6 (without writing this keyword), there is no ByRef keyword.
- It launches a created event, it can have a script, there are things that can only be done through it like autoscroll.
Tcreate scripts do not ignore the sleep function.
* EXESCRIPT AND TCREATEEX
- They are similar, they execute a local/global script (from the list of scripts, it is not a script function):
When this function is called, the current flow stops, jumps to it until it ends and returns, it has a parameter that is that of a script, despite having only one parameter, it takes the values of param1, param2, param3 from where it is executed, like when you are inside an npc script.
Be careful if you execute exescript inside a script that ignores the sleep function, this will do it too, as inside a NPCSCRIPT that ignores them.
When this function is called, the flow doesn't jump immediately, I'm not sure but I guess it will be executed after the last running npc script, it's like using tcreate but it launches only your script but without having to create the event, it has 5 parameters: script name, time it is launched, some parameter 1, 2 and 3.
The Tcreateex and Tcreate scripts do not ignore the sleep function, and they do not jump immediately.
- It's a keyword that you can prepend to a script function you created:
export script name_script(parameter1 as type1, param2 as type2, ..., return type)
Export makes a script function not forgotten: when you execute the function exescript, tcreateex and even tcreate, these functions will not forget the export functions of the script where they were executed, it is as if those export functions were defined within them.
What script "can't" run easily?:
- let's say like thiss: create my own function as "cos function" and be able to call it in any script, the only thing left is to copy it.
* Global script:
- A script that is saved in the world level can be executed with an exescript function.
- It is incomplete, inside these structs you can put scripts but when you put fields/attributes and try to use them, an error appears, it mentions them by calling them member variables.
- You cannot create classes, but there are classes that you can use, those classes are shared(nothing has to be instantiated) and by indexer, only their properties are used:
The objects of a class are used by index + a property, for example char(1).id=3
Some are created by design:
CHAR, BLOCK, BGO, WARP, LIQUID, NPC
There are other objects that are created by script:
BITMAP by bmpcreate
TEXT by txtcreate
EFFECT (in 1.4.5 path 31 you can access the properties) by fxcreate
NPC by ncreate
CHAR for cheats (like typing supermario8) * laugh
Others only control one important thing:
BGM(Unfortunately it disappeared in 1.4.5 or is it private? it seems that with mp3 this is lag.)
LVLTIMER(the time of your level)
Another one that is supposed to just read:
There is no class called:
LAYER, but can be controlled by functions:
-Lset: to make it disappear or make it transparent
-Lmove: to move it
-Lspin: to rotate
In 1.4.4 you could rotate and scale the screen like a bitmap but very strange and limited with the shaderset function, if you want to shake the screen a little bit in 1.4.5 you can use ‘call spevent(55)’
- In every box that requests event(event created) you can put a script, but it will ignore the sleep function(everything would be in 1 frame).
There are several boxes to put events, but you can only put script in the boxes of:
* In liquids type 10 and 11 (These scripts do not ignore sleep, they are not executed again until it ends)
* In the script box to create event (Read Tcreate).
* The NPCSCRIPT (While the npc is active, its execution is always launched, ignore sleep)
* In SMBX1.4.5, the NPC will create IMMEDIATELY after ncreate executed, so you can do something like this:
Code: Select all
a = ncreate(46, char(1).x, char(1).y - 256, 0, 0, 0, 0)
a = getid(a)
* CALLBACK (function in property/function in parameter)(or the closest)
- In the class NPC, BLOCK(the objects) has for example the deathevent property(and similar) if you put a script(from the list of scripts) it will ignore the sleep function, actually it is the box to put a created event.
You cannot define callbacks in a script function even though there is a keyword called SCRIPTPTR whose use is unknown,
What I know from VB6 is that callbacks are only to relate to c++ dll or api32, and should not be on a form(*.frm) but on a module(*.bas); also in VBA there is something curious there is a function called run: its parameters is a string that is the name of a function, the rest of the parameters are the parameters of that function sent to the string, which must be the same amount(function signature), in VB NET they are the delegates.