Scripting Introduction

WHAT IS A SCRIPT?

A script is a part of a file used by D3 that says "when this happens, and this is so, do this." The "when this happens" part is called the owner and event. The owner is the thing that gets happened to, and the event is what happens. The condition is the "when this is so" part. It is where you put the finer factors in the event. Such finer factors are what is doing the event, and the defining of some level events. The "do this" part is the perform the following actions. If the only thing under that category is "do nothing" you need to install D3-SDK.

WHAT WILL THIS TUT TEACH ME?

The basics to setting up a script. It will not teach you everything, but it give you enough to explore the almost limitless capability of DALLAS.

DO THIS FIRST:

The first things you will need before you try any scripting are the files that tell D.A.L.L.A.S. what to do and to compile the script. You can find the D3-SDK files here. Once you have downloaded it, follow the instructions in its readme files. Those files will tell you where to get the compiler. All of the files are free.

MAKE A LEVEL:

For this lesson we will be using the default level room. Find it by opening the new resource dialog box and selecting "new level, default room." I stretched the room out a bit by marking a few verts and moving them. You can use more advanced levels in your own experiments and works. Next, add an object, a robot. Any robot will do, but I recommend that you make it a fairly easy one. You will have to fight it. Make the robot be roughly 30 units away from the player start. Then select the bot and give it the name "bot." To name an object, select it. Then under the object window, near the top, is a window view of the object and its type. Note that the text of its type looks like it's on a button. It is. Click on the button. It should bring up a window asking you to name the object. This is where you type "bot" (w/o the quotes, D3E will add them automatically). You now have a level that can be scripted. SAVE the level. Make sure that the file name has no spaces in it.

DALLAS:

Just go to world view, then file>dallas graphical script editor. You should get exactly 2 errors the first time you open a new level. "UNABLE TO FIND levelname.CPP" "UNABLE TO FIND levelname.MSG" These are normal when you open up a level that has not been scripted. It's basically saying that the script files don't exist. This is because you haven't made them yet! From there, create a new script.

There is an easily labeled button for this in the upper half of dallas. Name the script "turn off bot." Set the owner, by right clicking on it, to level. Set the event to "level start." Set the condition ("if the following condition is met") to "ALWAYS." Finally, set the action to "replace with a new action">"AI">"turn [ON/OFF] AI for object {OBJECT}." This action is pretty self explanatory. If an action or query ("when this is so") is a bit harder to understand, look at the bottom of dallas. There is a box that contains information about the currently selected query or action. The action you just added should already be expanded. Right click on the variables that are in it. For this one the defaults are "OFF" and "None." Change the "None" to "bot" by right clicking again. (to change about any variable or such, right click on it). This is your first script. What it does is when the level starts it will turn off the AI (AI makes objects do things, all object that are not power ups have AI, not just bots) for bot. Now that bot will just sit there and make noise, we need to make a way to turn him back on.

Make another script. Name it "turn bot on." Set the owner to bot, the event to "collided with (IT)" (It) is a script wide (it is used in that whole script, but not the whole file) variable. (It) can be set to receive actions and be made so only certain ITs will work for the script. Set the condition to "replace...">"Binary statement with query">"objects">"[object] is a player." Leave it at its default settings. Note that the [object] becomes the [IT]. This means that if the object that collides with the owner (IT) is the object listed in the condition (is a player) the "when this is so" part has been set as "this is so" and D3 will then look at the actions section to see what it needs to do. You will have 2 actions in this script. Replace the "do nothing" with "turn [ON/OFF} AI for [object]" This is the same action you used in the other script, but we are going to change one of the variables this time. Set the object to bot again, but change the OFF to ON. Now right click on the header for the actions, not the action itself. Go to "add a new action"> "misc">"show HUD [message]." Now go to the message list area. Add a new message. Name it "boton." It should show "boton" in the upper box, and nothing in the lower box. Type, with out the quotes, cap sensitive, "GUIDEBOT: Bot's AI has been reactivated!" Set the message variable in the message action to "boton." This script will turn on the AI for bot when a player touches Bot.

For your final script, name it "end level," set the owner to "Bot" again. Set the event to "destroyed." For this query we do not need to add a condition. Replace the action with "replace...">"mission">"end level." This script will end the level when you have destroyed Bot. Save your script, it should automatically compile it for you.

NOW WHAT DO I DO?

Make an mn3 file like you normally would, but this time you need to add some extra files to it. Under the add files area, add "levelname.DLL" and "levelname.MSG." If this is the final release of a level, add the levelname.O file for Linux servers. Go play your level and touch the bot, which should be just sitting there. He will then come back to life and probably start shooting at you. :( You will have to kill him. After he is dead the level should end and you will be back at the main D3 screen. You have just made 3 scripts in a level.

The green highlighted area is the button to name an object.

This is my fully expanded script for this level.