[textwall : beginning]
Have you ever wanted to know just what the hell a variable is?
Have you ever seen some guy saying 'findclientbyname("asdf").setControlObject(123456); and said, 'What does that mean?'
Have you ever wanted to know exactly how the silly chat system gets onto your screen?
Have you ever seen some guy who had an auto-response script that could tell him the time, server name, and the current number of chat messages at once, and said, 'Boy do i want that?'
Have you ever wanted to play games in chat until you die?
Have you ever just wanted to know how to make client scripts that detect a message in the chat message system and respond accordingly (wut)?
Have you ever wanted to type hundreds of lines of script nonstop and have it client-sided? Or do you just want to know how to make something cool to impress your friends?
Then this tutorial is for you.
[/textwall]
TABLE OF CONTENTS :
Unit 1/-------------------------/About
Chapter 0/------------------/(Wtf chapter 0?) Credits! Credits! Ohcredittttssss
Chapter 1/------------------/Scripting? What is this 'scripting' you speak of, earthling?
Chapter 2/------------------/What are the uses of scripting?
Chapter 3/------------------/Wuzza chatbot?
Chapter 4/------------------/What can a chatbot do?
Unit 2/-------------------------/In the Beginning... The Backbone of Scripting
Chapter 5/------------------/Syntax, Syntax, Syntax
Chapter 6/------------------/Variables and what the hell they are
Chapter 7/------------------/The tragic tale of Client and Server
Chapter 8/------------------/Mishaps... The Crashbone of Scripting
Chapter 9/------------------/Other misc facts about scripting.
Unit 3/-------------------------/Diving into the olympic-size variable pool
Chapter 10/----------------/Array? What's an array?
Chapter 11/----------------/Variables around the Globe-al (or Local)
Chapter 12/----------------/Exported $goods*
Unit 4/-------------------------/Our first script, a client script! I bet you're happy.
Chapter 13/----------------/Where's the zip?
Chapter 14/----------------/.cs time!
Chapter 15/----------------/Running commentary
Chapter 16/----------------/Who made this thing?
Chapter 17/----------------/Initiating function alpha!
Chapter 18/----------------/Package in the mailbox
Chapter 19/----------------/Mama!
Chapter 20/----------------/Logical loops
Chapter 21/----------------/Testing, Testing, 123
Chapter 22/----------------/Daisy, Daisy...
Chapter 23/----------------/Sure-fire fix
Chapter 24/----------------/Testing, Testing, 456
Chapter 25/----------------/Success!
Chapter 26/----------------/Export to Return to Blockland
Unit 5/-------------------------/Chatbot
Chapter 27/----------------/Chat system and how it works
Chapter 28/----------------/Chatty parents
Chapter 29/----------------/I told you the if structure would be important later.
Chapter 30/----------------/A nice game of Roulette
Chapter 31/----------------/Schedule time!
Chapter 32/----------------/Do you want a break yet?
Unit 6/-------------------------/Q+A and user requests/an end to a good tale
Chapter 33/----------------/Hnnnnnnnnnn...?
Chapter 34/----------------/But mommy, i want it now!
Chapter 35/----------------/The File - Too lazy to make it yourself with this? Just grab the basic example and see the advantage for yourself.
Chapter 36/----------------/The Operators - How do i do math with console?
Chapter 37/----------------/The End - There, that wasn't so bad.
(Why is the ToC itself a gigantic wall of text? I'm confused.)
|||UNIT 1: About|||
==Credits! Can't forget them credits. Ohhhhhh crediiiiiiiiits, hum de dum, credits.==
ThinkInvisible|BLID 14511|Created this whole effin thing.
Bauklotz/Flaw|BLID 2107|He taughtethed me about Variables. Yay, Variables! Also helped me with a ton of stuff. Thanks Flaw!
Spockticus|BLID may be one of five|I learned some... well, a lot... of what i know came from rooting around in scripts. And i learned how to make chatbots with this guy's infamous 'What is Hex for ____?' script.
§RedWaterCat²§|BLID 12976|Inspired me to make this (*cough*made me make this*cough*) guide/tutorial.
==Scripting? What is this 'scripting' you speak of, earthling?==
Scripting is Blockland itself, of course. Scripting is the Garage Games engine that BL is made out of.
Scripting is a form of text that a programming language or game recognizes and calculates, returning the output of the input (what?) to your screen or to itself.
Basically, scripting is
http://en.wikipedia.org/wiki/Scripting_language.
==What are the uses of scripting?==
Without scripting, blockland most probably wouldn't exist.
However, even if blockland could exist without scripting, these features would be missing:
--Add-ons
--Server hosts doing kewl stuff
--Auto-updater(probably)
==Wuzza chatbot?==
A chatbot is a bot (robot) designed to detect chat messages and dump what it's programmed to say to reply to that chat message into the chat itself.
==And what is it's uses?==
Glad you asked.
A chatbot can:
Do math, handle games, handle a database, have a conversation, keep track of stuff, get data on the server you're in, autogreet, and much more.
Basically, a chatbot can do anything text-based or data-based.
|||UNIT 2 : In the Beginning... The Backbone of Scripting|||
==Syntax, Syntax, Syntax==
Okay, so there's one important thing you need to, absolutely NEED TO, know about scripting.
Scripting is very,
very,
really,
absolutely,
totally,
EXTREMELY, UNYIELDINGLY, VERY*ahem*... er... 'scuse me...
strict.
Syntax is easy to get wrong : the slightest misplaced character and, oop, nothing works. To fix this, you have to get these things right:
1. Always end EVERY command with a (); if there are no variables, a (vars); with variables, and in a special case a ;
2. Every [, (, {, and otherwise must always have a matching counterpart AFTER it.
3. = is only used in setting variables. An == is used to determine stuff. More on this later.
4. Never make an obvious mistake otherwise - always scan your script.
==Variables and what the hell they are==
A variable is, literally, a symbol, letter, or phrase representing another symbol, NUMBER(most common), letter, or phrase.
Now, what is a variable in Blockland?
A variable in Blockand is usually used to get a little piece of data. It can be set, and it can be retrieved. That's about it.
==The tragic tale of Client and Server==
Now, for our script, we will have to choose which of these to script with.
Client is run by an individual in ANY server, enhancing their GUI, chat, etc.
Server is executed during a server startup (duh) and enhances the entire server's gameplay. It may add a vehicle, it may be a new command, whatever.
So now, we are going to script with Client. It's easier, it's more useful to the general public that uses tons of different servers instead of hosting,
i don't know very much about server scripting you get the idea.
==Mishaps==
Scripting has its dangers. It can crash you, delete your files, crash your computer, it can even steal your key (Nobody knows how but that select handful of idiot hackers, but there's a way.)
Just a warning. Nothing like this will happen during this guide, but be warned. Experimenting can be super-dangerous.
==Other misc scripting stuffs.==
Scripting makes up only part of blockland. There's also GUIs, pictures, and models to deal with. But scripting is what makes all this necessary. So yeah, it's mostly scripting.
|||UNIT 3 : Diving into the olympic-size variable pool|||
==Array? What's an array?==
Okay, we're now entering... the variable zone. (DUN DUN DUNNNNN)
Okay, first off, an array is probably one of your most useful tools in variables.
An array is a way of stuffing hundreds of variables into one, like this:
$var1[1] = lol;
$var2[2] = wtf;
$var1[3] = omg;
$var2[4] = bbq;
but really, an array is mostly to slap a variable right into the middle of another one if you need to.
$val = lol;
$val2 = omg;
$wtf[val] = zorz;
$wtf[val2] = bbq;
Arrays are your best friend while exporting. Remember that for later.
==Variables around the Globe-al (or Local)==
Variables come in two flavors.
That's right, variables have flavors.
Variables can either be global (anything can get to these puppies) or local (sorry, it's private). However, there's more to it than that.
--GLOBAL variables are never erased until they're overwritten, deleted, or until Blockland resets.
--LOCAL variables are only used in small things, packaged within functions *more on those later*. They're deleted as soon as the function* ends.
Global variables are preceded by a $, whereas Local variables have a % before them. You'll most often find % variables in the start of a function, and $ variables in a set command ($ihazavarname = ihazavalue;).
==Exported $goods*==
The command export(); is your best friend if you want to ship something to a file.
Let's say you have a variable array $array1[values] and want to store ALL of those values in one teensy little file. Export to the rescue! Just say export("$array1*","config/testingmaistuffs.cs"); and zap those vars right to a file. The * in array1 means that anything after that is fair game for the export.
So, basically:
Say export("varname*","filepath"); to export to a file (duh).
The * means to include anything with the previous part and stuff after it.
The filepath is, of course, a filepath.
Varname is your variable.
|||UNIT 4 : Our first script, a client script! I bet you're happy.|||
==Where's the zip?==
Okay, so you see most add-ons packaged in a zip nowadays.
For testing,
DO NOT PUT IT IN A ZIP!Zips mess up testing and stuff. They're only for space-saving, and most WIP add-ons aren't zipped.
STEP 1 (Do stuff labeled like this, kids, it's imporrrrrtannnnnt.)
Make a folder named client_scripttutor in your add-ons folder.
==.cs time!==
All add-on files are .cs files if they're meant to carry code. I don't know what it means, client script, chat script, whatever. Just make a file.
STEP 2
Make a file in the folder client_scripttutor named client.cs and open it in Notepad.
==Running commentary==
Okay, so you're greeted by a blank screen. What now?
Well, it's always good to have, in comments, your name and BLID at the start of the file. And what is a comment, you may ask?
//This is a comment.
This is not.
This is not a comment //while this is.
//This is another comment.
//This is yet another comment and any code after me in this line will be disabled.
==Who made this thing?==
So, enter for the first line of your file:
STEP 3
Type into the notepad, ignore the quotes, they're just a placeholder -
"//Made by (your name), BLID (your ID)."
Make comments whenever something's unclear or when a fact needs to be stated.
==Initiating function alpha!==
Functions. You cannot script well without functions.
A function states several commands and scrunches them down into one command.
Here's an example:
function tripletalk(%var1) {echo(%var1);echo(%var1);echo(%var1);}
So when tripletalk(text); is stated in console, the console will say text back three times.
The syntax : function 'name'('arguments') {'code'}
Let's make our first function. By the way, this code will make your player say 'Hello world!' and then move forwards until you actually hit the forward key itself. Cool, no?
STEP 4 : Type into the notepad on a NEW LINE:
function initCmd() {commandToServer('messageSent'"Hello world!");moveForwards(1);}
By the way, commandToServer('messageSent'"TextGoesHere"); makes you say stuff. Cool, hm?
==Package in the mailbox==
A package contains stuff so it can be disabled and enabled.
Very useful.
The syntax is:
Package packagename {
codecodecode
codecodecode
codecodecode
};
activatePackage(packagename);
Say activatePackage(name); or deactivatePackage(name); to make it so codecodecode does/does not work, respectively.
Let's stuff our stuff into a package.
STEP 5 : Select the END of the first line in notepad and hit ENTER. Then type:
package testcommands {
And then go to the END of the entire file and hit ENTER to make a new line. Then type:
};
Make another new line and type:
activatePackage(testCommands);
That were a lengthy one. Onwards!
==Mama!==
Okay, you may have seen stuff about this before:
The parent:: protocol.
Basically, this lets you append code onto an existing command instead of overwriting.
We're going to skip this one for now, but it'tl be important later.
==Logical loops==
If structures, while structures, for structures. The basics of scripting.
These are conditional. If, while, for. You should be able to recognize them.
--IF - 'If' at the time the 'IF' command is running the variables stated by it are true, something happens. Otherwise, something else happens.
--WHILE - 'While' a variable stated in the 'WHILE' command is true, something will happen. If the variable becomes false compared to the set value, it stops.
--FOR - 'For' a specific amount of time, something happens.
These as well will not be included, but they'll be important later.
==Testing, Testing, 123==
Okay, now i'll show you how to test out this big thing.
First, there's one file we're missing.
STEP 6 : Make a file to go with the client.cs titled DESCRIPTION.TXT
and open it and type : "La de da description stuff."
For some reason Badspot wants us to have this file so we can't use this without a description.txt.
STEP 7 : Hit SAVE on Notepad to save the client.cs, and start a Blockland server. Single player.
STEP 8 : Say initCmd(); in console.
==Daisy, Daisy...==
Oops. It seems an error was made!
Press ` (the console key) and scroll way up. Waaaaaaay up.
Keep going until you see RED, near the start. Make sure it says that it's executing your mod, and not something else. If it says something else, keep going.
Syntax error?
Sorry, but i made an intentional error. It seems i want you to fix it :3
The commandToServer('messageSent',"text"); was infact missing the crucial comma! ^ Right there, see the little guy?
==Sure-fire fix==
Open the .cs file again and edit the comma in, and hit Save. DO NOT close the blockland server:
STEP 7 : Open the file again without closing the blockland server. Put the comma where it should be, save, and close.
==Testing, Testing, 456==
Okay, here's how you reload it ingame.
STEP 8 : Reload the add-on by saying in your console (`):
exec("add-ons/client_scripttutor/client.cs");
This code will run the code in your file, and it should rewrite the old one sitting around in the RAM or whatever it is.
==Success!==
Say initCmd(); again. Did it work? Good!
(If it didn't, you're horrible at instruction-following. Go away.)Don't you feel proud of yourself?
Let's show you how you can export it to RTB, just incase you make a REAL add-on.
==Export to Return to Blockland==
--DO NOT actually do this with your add-on. This is a TUTORIAL add-on and should not be released.--Okay, first you put the add-on into a ZIP file. This is the only time it's okay to do this without it being a waste of time. Now, go on RTB and make an account if you don't have one already. Find the fileCP and click on Upload Add-on. Follow what the text there says until you come across the file upload screen. Click browse or whatever it is and find your zip file. Not the folder or .cs, the zip file. Upload that and keep following the text, and you're good to go!
Wasn't that interesting?
Well, that wraps it up for our first script. You can go delete it or something now.
Prepare for second post! Awaaaaaaaay!