BSL:Tutorial/Scratch

From OniGalore
Jump to navigation Jump to search

This page is a short tutorial on how to get started on simple scripts for those who have had no experience with scripting before. It will teach you, step by step, how to write a simple script. By the end of this tutorial, you will be able to move on to more advanced scripts.



Part 1 : Knowing your formats

The game will accept 2 types of syntax for scripts, and they are based on different styles of writing. Choose the one that suits you best.

The types are :

Shell-Style: This is compiled much like some System-Shells. It is written in a "one-function-call-a-line" format, and is the easiest to begin with if you have had no coding experience, as the code is neatly displayed line after line. The downside of this it, that once you get into more complex scripts or scripts with many function calls, the file becomes very hard to read and very large.

Example: Shell-Style

C-Style: This is compiled much like the popular coding style C. The syntax can be placed into multiple-function lines and functions are divided by a ; . In advanced scripts, this style will allow you to condense your script and the parts will be easier to read/debug. It also allows you to utilize some of the more advanced features easily. The problem with this is, that starting off, it is harder to write if you have had no previous experience with coding.

Example: C-Style

For the purpose of this article, we will use Shell-Style syntax for simplicity.



Part 2: Starting Off

Now, I suggest reading the original script files to get a basic idea for how scripts are laid out. This will allow us to jump-start a bit.

Open up your IMGD and look for the following folder: EnvWarehouse. Open it up, and we'll take a look at how it it laid out. There should be several files in here. Open using NOTEPAD, the one titled warehouse_main.bsl. It should look like this:


func void main(void)
{

   env_show 2010 0
gl_fog_blue=.15
gl_fog_red=.15
gl_fog_green=.15
gl_fog_start=.99
gs_farclipplane_set 5000
obj_create 20 20
level_start


}

This is an example of a main file. It contains the information of how the level starts.

Ignore the contents of the script for now, and notice that the contents of the function main are enclosed by a set of brackets ({ and }).

All functions must be enclosed in this set of brackets or it will not be executed.

Close the file, and rename the folder "EnvWarehouse" "EnvWarehouse_original". Then, create a folder called "EnvWarehouse" and create a script file inside and name it "Tutorial". We will be using this file to show various examples of scripts and finally, write a small script of your own.



Part 3: Basic Commands

This is just a small section explaining the commands that will be used in this tutorial. For a complete list of commands, see Ssg's Site for more information.

ai2_spawn (name) - creates and starts an AI from a character object
chr_teleport (name) (flag) - teleports a character to a flag
chr_givepowerup (name) (powerup) (amount) - gives a character a powerup
. . .



Part 4: First Script

This section will teach you how to write a very basic script (fighting script). It will start you off in the Final Training Room, where you practiced firing weapons in the original game. With this script, the room will appear very empty.

Let's open up the "Tutorial.bsl" file and start writing the script.

First, declare it the "main" portion of the script by typing "func void main(void) at the very beginning of the file. This tells the game which function it is. The "main" function is the function that the game looks at first to determine what is to be executed.

Below that line, type {. This tells the game that the function has started.

Add a space, and then type chr_teleport 0 7010. This function teleports Konoko (her id is always 0) to the flag 7010. It is located in the final training room.

Finish the function "main" by typing } on the next line.

It should look like this:

func void main(void)
{
chr_teleport 0 7010
}


Save the file, load up Oni, and click "New Game". You should be standing in the center of the final combat training room.

You are now on your way!



Part 5: Adding NPCs (AI)

Before we begin, notice that there are two types of AI. AI created from character objects, and AI created from memory. AI created from character objects are created by the function call ai2_spawn (name), where (name) is the name of the AI. AI created from memory are created by the function call chr_create (ai_number) start,. These AI do not have combat logic, and thus will not attack you physically but can still use weapons.

Now, we are going to add 2 enemy AI to our script that we wrote in the last section. Open it up, and lets add some enemies for Konoko to fight.

To recap, it should look like this :

func void main(void)
{
chr_teleport 0 7010
}

After the function call chr_teleport 0 7010, add the following 2 function calls on separate lines: ai2_spawn Top_Striker and ai2_spawn Top_Comguy. These two function calls tell the game to create 2 characters: Top_Striker, and Top_Comguy.

Since that these characters do not spawn in the room, they must be teleported there. Using the chr_teleport function call used earlier to teleport yourself, modify it to teleport the 2 AI using their names instead of "0". Teleport them to the flags "7008" and "7009" respectively. Refer to the example above or the list of function calls above to write this in.

It should now look like this :

func void main(void)
{
chr_teleport 0 7010
ai2_spawn Top_Striker
ai2_spawn Top_Comguy
chr_teleport Top_Striker 7008
chr_teleport Top_Comguy 7009
}

This script will now teleport you into the final training room and face you off against 2 Strikers.

This fight too easy? In the next section, we will learn how to spice up the fight, and let you develop your own script.



Why isn't it in the OSL namespace???geyser 06:04, 15 Nov 2005 (CET) Changed (?)

                                                             - Your_Mom