Text Based Scripting
From Wiki001
Text Scripting is a more complex mode of scripting rather than using the Event Based Scripting. It's rather harder, but if you're good at it, you'll be able to script faster, without mentioning that you can do some cool stuff that is current not possible with EBS at the moment, like certain kinds of looping.
!!!NOTE!!! TEXT SCRIPTING IS CURRENTLY NOT RECOMMENDED FOR USERS
Contents |
Advantages and Disadvantages
Advantages
- Working with more complex algorithms, it might be confusing to not use text based scripting.
- Many features, such as listing the possible objects and listing the options for a command, is available to text based scripting as it would be in the event based scripting.
Disadvantages
- Often, tedious tasks such as working with multiple objects can easily be accomplished with event based scripting.
- Certain functionality is simplified for good reason in the graphical scripting. For example, the Advanced Message Box will figure out the number of columns for the choices based on what you fill out. This task could easily be confusing if you were to do it by hand.
- You'll miss out on certain things like the rotation picker and color picker.
- The most important thing to understand is that everything in Text Based Scripting can be done in Event Based Scripting. So often, time could be wasted even learning text based scripting.
Variables
Variables are the key of a well-developed game. With variables you're able to make quests, make characters say different things whenever you talk to them, etc.
There are 3 kinds of variable:
Global Variables
These are variables that can be changed any time of the game, they'll always work. They can be changed through the Variables section under Scripting within your project.
Local Variables
These are inputed on certain scripts, and work for them only. Their values are discarded whenever the script ends.
To create local variables, go on your script and press the button 'Create Local Variable', or go on text scripting mode and type on the first lines of the code:
LOCAL myvariable
Static Variables
Also inputed on certain scripts, except that its values are NOT discarded after the script ends. They don't count as a global variables, since you can't access them from other scripts.
To create a static variables, go on text scripting mode and type on the first line:
STATIC myvariable
Note: Static variables are only available in text based scripting.
Working with Variables
To operate a variable simply use the code:
SET yourvariable = x
Example:
SET orange = orange + 1
Recently added is the ability to make a variable transition over a period of time. In the following example, apple is increased by 100 over a period of 1000 milliseconds (1 second):
LERP 1000 SET apple = apple + 100
One can also use the LERP keyword to transition properties that are colors and properties that are angles, avoiding common issues, such as dealing with individual color components and making sure that one is rotating in the best direction.
Math Functions
While working with variables, you will use a lot of common functions, like addition, subtract, multiply, division, etc. The more uncommon functions will be explained here.
Using Brackets
This is a small briefing of how to use brackets. Everytime you add a left bracket, a right bracket must be added too, or the script will fail. Brackets are often used to set the priority level of which math function should work first. Example:
SET var1 = 5 SET var2 = 1.5 SET var3 = 100 SET var4 = 20 SET var5 = 0.5 SET random_formulae = (var1 + var4 -(var3 * var5 ^ (var2 + var5)) - var1 * var4)
Note that for every left bracket, there's a right bracket too.
Integer Portion
This function gets a number and keeps its integer portion only.
SET myvariable = Math.Int(5 * 3.1416)
Absolute Value
This function will return the number's absolute value.
SET myvariable = Math.Abs(- 25 ^ 3)
Percentage Deviation
This function will either ADD or SUBTRACT up to X percent of your number.
SET myvariable = Math.DeviateP(5000, 100)
Note that the first number is the variable, and the second is the percentage deviation.
Random Number
This is one of the most powerful functions, it will return a random number. Minimum and maximum values are defined by the user.
SET myvariable = Math.Random(1, 100)
Sine, Cosine and Tangent
These mathmatic functions may not be used by everyone, but they're still very important ones. The number returned is the corresponded value of the angle in radians for each function.
SET myvariable = Math.Sin(3.1416) SET myvariable_2 = Math.Cos(0) SET myvariable_3 = Math.Tan(5.4978)
Respectively 180º, 0º and 45º.
Conditions
This is pretty much the MOST important feature and the one you'll use the most while making your game. It will always return TRUE or FALSE.
On text scripting, a condition structure is composed of the following:
IF, ELSEIF, ELSE and ENDIF
Note that ELSEIF and ELSE are not obligatory.
Also, you can use different operators to compare expressions:
= (equal) <> (not equal) >= (greater or equal to) <= (lesser or equal to) > (higher than) < (lesser than) Like (similar to)
You can compare more than one expression too, using:
And (all the expressions must be TRUE or FALSE will be returned) Or (one of the expressions must be TRUE or FALSE will be returned)
Example - Angering someone off:
STATIC times_talked
IF times_talked <= 5
MsgBox.Show("Man: Hello.")
MsgBox.Hide
ELSE
MsgBox.Show("Man: MOVE OUT I'M BORED OF YOU!")
MsgBox.Hide
ENDIF
SET times_talked = times_talked + 1
Example 2 - Forging a sword:
LOCAL have_iron
LOCAL forging_skill
SET have_iron = Char("main").ItemCount("Iron")
SET forging_skill = Char("main").Stat("Forging Skill")
IF have_iron >= 100 And forging_skill >= 10
MsgBox.Show("You've forged a sword!")
MsgBox.Hide
Char("main").AddItem("Iron", -100)
Char("main").AddItem("Sword", 1)
ELSE
MsgBox.Show("You either don't have enough iron or forging skill.")
MsgBox.Hide
ENDIF
Switches
Switches are just like variables, the only difference is that they only have "ON" and "OFF" values. On Text Scripting, to operate a switch simply input:
SET yourswitch = "on"
Or
SET yourswitch = "off"
And to refer a switch using the comparison branch use the following structure:
IF yourswitch ELSE ENDIF
Note that there's no need to use IF yourswitch = "on" in this case.
Loops
Looping consists in running a script repeatedly times, can be a useful feature if you want to sum up several lines of coding into a few ones. To create a looping spot, input in a line of code:
:myloop
To go to that loop, just input the following:
GOTO myloop
It's as easy as that. Now playing with it you may find some cool stuff, like: imagine you have a map with 20 enemies that spawn at once, and their names are Man 1, Man 2, Man 3, ... Man 20. Look how you can spawn them with a few lines of code.
LOCAL spawned_characters
:spawn
IF spawned_characters < 20
SET spawned_characters = spawned_characters + 1
SET Char("Man " & spawned_characters).NonExistent = 0
GOTO spawn
ENDIF
Note that " & spawned_characters is a feature that allows you to input variables within an object line, a very useful one.

