Information: The difference between scripts and Scripts

From PBnWModdingWIKI

There's a difference between scripts.. and.. scripts. When people talk of scripting or scripts, they might refer to either or both of these:

Contents

The concept of scripts

On the subject of scripts, Wikipedia writes:
Scripting languages (commonly called scripting programming languages or script languages) are computer programming languages initially used only for simple, repeated actions.
Many such languages are quite sophisticated and have been used to write elaborate programs, which are often still called scripts even though they go well beyond automating simple computer tasks. A script language can be found at almost every level of a computer system. Besides being found at the level of the operating system, they appear in computer games, web applications, word processing documents, network software and more. In many ways, the terms high-level programming language and scripting language have become entwined, and there is no clear delineation between the two.
This is somewhat true for B&W2 scripting, as its scripts are like mini programs designed to do something in the simulated universe that is B&W2. For example, the FPS script is designed to allow you to walk around in 1st person. This is a script. You compile the script.

begin script MyScript

Oh. And here is where the confusion starts. This is the syntax to start a block of code that does something. It's identified by the name MyScript, and it can be called with run script MyScript. Lionhead calls these blocks of code 'script'. That is, of course, true. Technically, that's script. However, it's 'script' in the practical sense, and not in the theoretical sense, like, the concept of scripts.
I prefer to refer to these blocks of code as methods. Most programmers will. Sometimes people call them 'functions', that's okay, but functions usually refer to the commands you use in your script. (Like do this and go there).

Okay, okay, I get it. You got Scripts and scripts!

Exactly. Now, this means that there are two ways of implementing Kalev's FPS script! Or any other script. It depends on the script which way you'll want to use.

The Ancient And Somewhat Sacred Way of The Challenge List

The B&W2 script compiler doesn't magically find your script files. It reads them as a list from your challengelist file. Read more about that here.. So if you already have a script that does something, and you want to add a standalone script, such as Kalev's FPS script, just add it to the list of files. Put Kalev's sourcecode in a textfile named kalev.txt, copy the previous entry of your challenge file and add kalev.txt. So if you followed the Getting Started tutorial, and you wanted to add Kalev's script to that, your challenge file would look like this:

Code:

wikitutorial/WikiTutorialScript.txt
wikitutorial/kalev.txt

(Note the blank line on the end! Important! It's just one line, though. Not two.)
Now, of course there are some pitfalls, but if you run into one then IRC and the forums are a great way to get help.

The Way of the Methods

Catchy title, that. Now, say, someone gave you a script with a nice method, the method unlocks all of the buildings and stuff. It'd look something like this:

Code:

global ILikePie = 1
run script UnlockBuildingsAndStuff

begin script UnlockBuildingsAndStuff
  //These are variables. Like, things that remember other things.
   oBuilding1 = 0
   oBuilding2 = 0
start
   //Some comment, this gets ignored by the Compiler.
   //Usually used by the programmer to explain his code.
   //Mind, this is not actual code. It will NOT compile!
   Use Some Script Function To Unlock BuildingX
   Use Some Script Function To Unlock BuildingY
   Some More Code
   Some More Code
   oBuilding1 = Create Some Building At {L0,C4T,10N} 
   oBuilding2 = Create Some Other Building At {L0,C4T,10N} 
   Destroy oBuilding2
   Paint oBuilding1 its Door COLOUR_BLACK
   If Some Condition is Met Do
       Some Interesting Stuff
   End If
end script UnlockBuildingsAndStuff
Well, you could use the Way of the Challenge List and just add this file to your challenge list (however, it needs to be listed BEFORE any other script that uses the method in that script you're adding, otherwise the compiler will run into problems.)
However, with just one function, that's not really desireable. Anyway, if you did the Getting Started tutorial and paid attention to the Writing The Script section, you'll notice that you need to call run script SomeScriptName to get it running. That's called, calling the method. So, what you can do, is just copy that block of code from the begin script part all the way to the end script part, and add it to your own code. If that doesn't make sense, you'll need to learn a little more about scripting languages. That's okay, you now know what methods are, so whatever you're going to do, you're going to add that method to your own script. If you still run into trouble, think blocks. Just like Lego, you need to make it all fit, intersecting of blocks will cause a meltdown in the universe as we know it.
So our WikiTutorialScript.txt file ends up looking like this:
global ILikePie = 1

run script WikiTutorialScript
run script UnlockBuildingsAndStuff

begin script WikiTutorialScript
start
	disable load screen
	set fade in time 1
	wait until 1 != 1
end script WikiTutorialScript

begin script UnlockBuildingsAndStuff
  //These are variables. Like, things that remember other things.
   oBuilding1 = 0
   oBuilding2 = 0
start
   //Some comment, this gets ignored by the Compiler.
   //Usually used by the programmer to explain his code.
   //Mind, this is not actual code. It will NOT compile!
   Use Some Script Function To Unlock BuildingX
   Use Some Script Function To Unlock BuildingY
   Some More Code
   Some More Code
   oBuilding1 = Create Some Building At {L0,C4T,10N} 
   oBuilding2 = Create Some Other Building At {L0,C4T,10N} 
   Destroy oBuilding2
   Paint oBuilding1 its Door COLOUR_BLACK
   If Some Condition is Met Do
       Some Interesting Stuff
   End If
end script UnlockBuildingsAndStuff

Origin

From this thread, written by me.

Author

--ShadowCode 03:04, 16 March 2006 (PST)