BYOND TUTORIALS
BY ADAM R. TURNER
HELLO WORLD!
-Tutorials for non-know-hows from the in-the-know.
At the time of this writing I've been feeling pretty lazy; it's also 1:51 AM. However, it hardly matters because Hello World program's in BYOND couldn't come easier.
Some things in this tutorial you might not understand at first, but the key to learning code is to recognize that all things come together eventually. The more you practice and write code, the more you read about it, the clearer your vision becomes and eventually, you'll be able to assemble this program and others like it as if you were the great Houdini playing against a toddler at Chinese checkers.
Let's become acquainted with <dm> and </dm> tags. On the BYOND forums, if you have a question about the code you're writing, you need to encapsulate your code between the DM tags. You're much more likely to acquire assistance if you observe this rule.
Example:
| <dm> //Your code here </dm> |
To get started, open up Dream Maker, and select "New Environment...". From here we have 2 options, the directory and the name. If you decide to change the directory, remember where you put it. After that give your project a name, "Hello World" will do, but you can call it something else if you feel so inclined.
BYOND will automatically generate your first code file for you, it will be aptly named after the name of your project. It should be automatically selected for you to work in, so we can get started right away.
You may have noticed the double-slash marks above: //Another tool to encapsulate code in comments that is used to easily hide multiple lines of code from the compiler (Dream Maker, in this instance) are: /* and */ .
Example:
| /* Your code here. */ |
A datum is a structure that contains information. The first one we have to learn about is the world datum. Datums allow us to easily keep distinct various operations within a program. In general, they keep things from getting confusing and allow us to manipulate a whole body of code in a single operation.
Now that you are in the code file for your project, start with the world datum like so:
Example:
| world //The world datum name = "Hello World" //The name of our world. hub = "Rockinawsome.Hello World" //This is so it will show up in your hub when you register the game. |
By following what comes after the // marks, we see what's going on above. We have the datum, followed by the name, followed by the hub address. In BYOND, we must indent things to what they belong to. The amount of indentation must always be the same for a given item, if they are not - you will get what is known as a compile-time error when you try to compile. For a programmer familiar with brackets and semi-colons, these can be used as well, if you're not familiar with them - don't worry - they wont affect your ability to code properly.
Do you see how name and hub belong to world? That's because these 2 items are variables: items that can be changed and affect whatever they belong to. In computer memory, these variables are assigned various addresses, and those addresses store whatever information we need the computer to give back to us later. Most languages require us to facilitate various forms of variables for certain things, in DM these things are automatically taken care of for us as long as we adhere to the simple and obvious syntax. For example, the variable name is proceeded by an equals sign and the line of text we wish to assign to it are surrounded with quotes. This tells the compiler that name should equal a text string called Hello World. FYI: A text string is simply a line of text surrounded in quotes, the name is given to it because the characters or letters are strung together. A variable can equal a number, a list, or even another datum as well (but we'll deal with those later).
Unlike datums, procs - short for procedures - execute code instead of storing it. Whatever is placed in a proc, will be executed when we run our program, or when it is called. Some procs are called automatically, or are built into BYOND for us, for others we define them ourselves (see tutorial 3). world/New() is a proc which belongs to the world datum. Whenever a datum is created, New() will be called. Whenever a program is executed (i.e. run), world/New() is called (e.g. executed).
Example:
| world //The world datum name = "Hello World" //The name of our world. hub = "Rockinawsome.Hello World" //This is so it will show up in your hub when you register the game. New() //The New proc ..() //Call the already defined proc sleep(1) //waits 1/10 of a second before running the code, it gives the proc a chance to load the world first world << "Hello World!" //for all player mobs in the world, send them the message "Hello World" and print it to the screen. |
Above we have called the proc New(), the proc is a proc because it has been defined for us, and because it has two parenthesis after the name. The code to be run is indented after New(). The output operators << are like arrows, they point the text string in the direction of where it should go. To see your code in action go to the 'Build' tab at the top of the page and select Compile (shortcut: ctrl + k). After no errors are returned from the compiler, revisit the Build tab and select Run.
Hello World! should output to the screen.
>> Mob Creation (Next Tutorial)
More questions? Consult the BYOND forums or your reference by pressing F1.
Email me at adam.empyreal@gmail.com if you have any comments or suggestions.