02MORPG: Making an MORPG with BYOND

by Ter13
Learn to make a MORPG with BYOND with no existing knowledge
ID:2148785
 
If you have not already, download and install BYOND. I recommend the latest beta if you are actively writing software with BYOND. Stable builds can be months out of date, and beta versions are typically stable enough for development. This is not always the case. Some instability in beta versions is to be expected.




1.1: A Step BYOND

  The BYOND software suite includes Dream Maker, Dream Seeker, Dream Daemon, and the pager.


  Dream Maker is an IDE, or an Integrated Development Environment. More or less, it includes everything you need to create a game with BYOND including a graphics and animation editor, a map editor, an interface editor, and a source code editor.

  Dream Seeker is a game client for connecting to games made with BYOND. Dream Seeker communicates with Dream Daemon by taking a player's input and sending it to the server, and receiving instructions from the server for what is going on in the hosted world. This exchange of information is called a user interface.

  Dream Daemon is a game server. Game servers maintain information about what is going on in a particular game and drive the information displayed to and collected from connected clients.

  The Pager is a tool for accessing the BYOND hub, a sort of publishing service for BYOND games. It also provides a limited messaging service between registered users. Users can keep track of their favorite games using this service and receive notifications of when they are live, or when their friends have status updates much like most other instant messaging software.


  Let's go ahead and open Dream Maker once you have it installed.




1.2: Meet Your (Dream) Maker

  Dream Maker appears pretty empty when you first open it. We need to create a new project first, by clicking on the File menu and selecting New Environment...



  A dialogue box will open, asking for a Directory and the name of the new environment. I like to use a special folder in my documents directory for BYOND projects. You can create a new location by clicking on the ... button. The environment will create a new subfolder within the chosen directory with the name you enter in this dialogue box provided that it does not already exist. Go ahead and choose whatever name you would like for this project and press the OK button.



  Another dialogue box will open, asking to create a new code file. You can name this anything you want. This will auto-generate a code file containing the simple defaults for a typical project. Press the OK button.



  Now that this file has been created, it will populate with some code in the right panel. This code is called DM. DM is a simple C-like programming language that is designed to be fast and easy for beginners to grasp, but don't be fooled, it is quite flexible and powerful to the point that it demands a lot of study and experience to master.



Let's introduce the three main areas of the Dream Maker IDE.

  1) This is the File and Object browser. You can see what is included in your environment folder in the File browser in a handy tree-like format. Checked files are included in the final project. The object browser shows the object tree. We'll cover what this means later.

  2) This is the document area. The document area varies based on what kind of file you are editing. DM includes a handy code editor, an animation and sprite editor, a basic map editor, and an interface editor.

  3) This is the log. Messages generated by the IDE during use will display here. This will be your worst nightmare soon, but when you learn to use it, it will become your best friend.




1.3: Mak Gam!

  You may be looking at that code in the document area and thinking to yourself that you are a little bit lost. That's fine. You are attempting to read source code! Nobody starts out able to understand it. It takes time and memorization. Eventually, you'll be able to read this like you would English.

  So what does source code have to do with games anyway? How does source code make a game? Well, that varies based on the language. For now, we're going to only talk about DM, but remember that not all programming languages follow the same rules that DM does. Source code is a human-readable, generally human-written series of instructions that are interpreted by a piece of software called a compiler. The compiler takes the source code and produces a processed version of it that is much less flexible. Source code's purpose is to be easy for human beings to read and write. Machines, on the other hand, work very differently than humans. They don't need whitespace between symbols. They don't need newlines, and they don't need words. A compiler breaks everything down into numbers encoded in binary. Dream Maker's compiler, DM.exe, compiles the DM language found in .DME (DM Environment) and .DM files into something called a .DMB (DM Binary). Dream Daemon is a special program called a virtual machine that transforms the DMB's encoded instructions into a working game!

  So let's recap really fast. A programmer is a person that transforms Mountain Dew and Cheetos into source code using an IDE. A compiler takes the source code written by the programmer and turns it into a binary. A virtual machine runs the binary, at which point the code becomes a game. You->Dream Maker->>DM.exe->Dream Daemon>->Game. That's how you make a game! Thanks for joining us for this tutorial! That's all there is to it!




1.4: Hello World!

  Actually, I was just kidding. There's a lot more to it, but that's the basic process you are going to follow when making games with DM. Let's make our first piece of software with DM. Every programmer starts in roughly the same place: Hello World.

  Go ahead and delete all of the code that Dream Maker nicely generated for you in the file that you just created. Don't delete the file itself, just select all of the code and hit delete until there is nothing left.

Let's add our own code to it:

Whitespace delimited:
mob
Login()
world << "hello world!"


Pay careful attention to the way that this code is formatted. Login() is tabbed once under mob, and world << "hello world!" is tabbed once more under Login(). This is called scoping. BYOND is a flexible language, though, and allows many forms of code to do the same thing.

Path delimited:
mob/Login()
world << "hello world!"


Token and whitespace delimited:
mob{
Login() {
world << "hello world!";
}
}


Token delimited:
mob{Login(){world<<"hello world!";};}


The above two variants are also valid ways to write this code. DM is a very flexible language. If you would prefer to use curly brackets and semicolons, that is very much up to you. I prefer to not use them, however, in most places in DM because they make the code look much less readable. I prefer the whitespace delimited format.

  Now go to Build->Compile (or press Ctrl+K)



  Now go to Build->Run (or press Ctrl+R)

  You should see the message hello world! pop up in a nondescript white window that opens after you run the compiled environment. This is Dream Seeker.



  If you run into any errors, check and recheck that your code exactly matches my first example. Make sure that you are using tabs and not spaces, and make sure that everything is spelled and capitalized EXACTLY as you see in my example. The compiler is not a mind-reader. You have to be very precise with what you type or it will fail to compile. For example, I made a simple mistake here and attempted to compile:



  The compiler attempted the compilation, but encountered an error and set that error message to the log. You can double-click on this error to jump to the line where the error occurred. In this case, I simply didn't capitalize Login(), and thus the error occurred. Programming requires precision. Troubleshooting is hard and frustrating at first, but stick with it. Always assume that you made a mistake somewhere along the lines. Never assume that the software is just broken. Walk through your mistakes line by line and if you run into trouble you can't think your way out of, swing on by Developer Help on the BYOND forums and we'll set you straight.

  Hello World isn't much of a game, I know, but let's walk through the code to figure out why this works.

  mob is the first token. mobs are short for mobile objects. Mobs are one of four primary built-in objects we will cover first in this tutorial series. They act as a sort of avatar for players, and often as non-player characters that players can interact with. Mobs are how players see, touch, and hear your world.

  Login() is the second token. Notice how it's tabbed under mob? That's because Login() belongs to mob. The token () indicates that Login is a function token. Functions are groups of code that execute when the token is invoked. BYOND, by default invokes Login() when a player connects to the world and assigns them a mob.

  Notice how the rest of the code is tabbed under the mob's Login function? That's called the function body. The function body is a group of instructions that are executed in order top to bottom one after another. In this case, we are outputting "hello world!" to the world. What's world? world is an object too! world is a built-in object that describes the currently hosted game session on the server.

  So what's "hello world!"? Hello world is text, but it's a special type of text because it is surrounded by double-quotes. When text is surrounded by double-quotes, it is called a text string, or string for short. Strings are a method of representing digital data as human-readable symbols in computer software. That's a lot of words to mean simply: strings can be words. Anywhere you want to display text to the player, you are going to wind up using strings. They are not objects, however. They are called primitive data types, or just primitives/prims for short. Primitive data types and objects are different in that primitive data types do not own functions. Primitives are just raw data and do not have any real code associated with them.

  Lastly, there's one symbol we haven't covered: <<. The << symbol is an operator. Operators are used with values to perform operations. Both objects and primitives can be manipulated as values. The << operator is called the output operator. The output operator comes between two values, which are called operands. An operand is just the generic term for a value that is used in conjunction with an operator. In this case, the output operator takes a left and a right operand. The left operand is world. The right operand is "hello world!" (a string). Certain objects can take certain types of values as output and do different things with them. In the case of the output operator being used on the world object with text, the text string in the right operand position is sent as a message to every player currently logged into the world. Cool, right?

  So let's learn to read this:

"on mob Login, output string "hello world!" to world."

mob
Login()
world << "hello world!"



"on mob Login":
mob
Login()


"output string "hello world!" to world."

world << "hello world!"


  If this isn't making a lot of sense to you yet, stop and reread the above section again. You aren't going to get it on your first try. Copying is easy. Understanding is hard. But in the end, understanding is the goal. Doing comes from understanding. Without understanding, you will not be able to make whatever project spurred you to read this tutorial.




1.5: Hello Map!

  In the last tutorial, we learned to create a simple hello world project to demonstrate how easy BYOND is to use. Let's set up a basic graphical MUD and get the character walking around. First, we're going to need some basic graphics. Let's create a new icon file. In DM, sprites and tiles are both called icons. Icon files are a series of animated icon states that you can flip between easily. DM's DMI format is just PNG with special data stored in the zTxt block of the file (if this is Greek to you, don't worry. This isn't all that important to know until much later in your career). In fact, you can use PNGs as icon files in DM as well if you would like.



  Now that we've created our icon file, we can give it some fancy graphics. Let's set the size to 16x16 by using the input area at the top right of the editor, and then right click on the white space in the middle and select "New Pixmap...".



  The next step is to create your lovely art. I'm using the awesome DawnLike set by DragonDePlatino for this tutorial. You can do the same if you'd like. There's nothing wrong with placeholder art to get you started! Just make sure you give credit to the original artists and follow their licensing requirements! You can copy and paste into the DMI editor from whatever image editing software you prefer. The DMI editor is really only good for animating, and even then it's a bit feature poor. Invest in a good pixel art software if you plan on making a game with BYOND. You'll save yourself a lot of time and effort later.



  Let's also do the same for some grass tiles, except this time we're going to right click on the grass tile we create and select Edit State... Set the name of the state to the number 0 and press OK. We just named an icon state. icons can contain multiple different graphics all grouped into one file. They all have to be the same dimensions, but they can vary in the number of frames of animation and display direction. Naming a state allows us to use a specific state from the file.







  Next, we need to jump back into the code editor. Let's delete the hello world code completely and start fresh.

mob
icon = 'Graphics/Sprites/player.dmi'

turf
icon = 'Graphics/Environment/tiles.dmi'
icon_state = "0"


  The above code is a form called definition. Do you remember that mobs are objects? Also do you remember that there are four basic types of objects in BYOND? Turfs are the second basic type of object. Turfs represent one square on the map, often called a tile. Both mobs and turfs have icon and icon_state variables. But just what is a variable? A variable is a defined place where you can store values. Remember values? We know of two of them at the moment, strings and objects. Strings are identified by double-quotes. Notice how our icon_state uses double-quotes? the icon_state variable is supposed to store a string identifying which state in the icon file of the current object to use for drawing. Icon is another variable, but this one is not a string. Single quotes mean that the value is actually a file or resource reference. In this case, we're storing an icon (DMI) file in the icon variable of both mob and turf. File references are another primitive, in that they don't own any variables or functions. Objects are basically a collection of data that can own variables and functions.

 &emsp: Those equals signs (=) are new too. What about those? Well, as you may have guess, that's an operator too, and just like the output operator, it takes a left and right operand. The left operand is the variable that we will be setting the value of, and the right operand is the value that we will be assigning to that particular variable. This is called the assignment operator. We are using it to tell the mob and turf objects to have default values for their icon and icon_state variables. This gives them visual appearances when seen on the map.

  Compile the code and then create a new file. This time, let's create a map file. Set the dimensions to 50x50x1 and press OK.







   You may notice something doesn't look right. The tiles are too small to cover the available space of every square. BYOND defaults to a 32x32 pixel tile size, and we want to use 16x16. We need to tell the engine that we're using a 16x16 tile size.

world
icon_size = 16

mob
icon = 'Graphics/Sprites/player.dmi'

turf
icon = 'Graphics/Environment/tiles.dmi'
icon_state = "0"


  You'll notice that world showed back up in our code again, only this time it isn't inside of a function body. Well, sometimes the same token can have different meanings. When using world inside of a function body, you are accessing the world object or its properties (vars/funcs). When using world outside of function bodies, though, you are modifying the object's prototype. Remember this term for later. We'll go over it in a later section. For now, just compile again and run the project.



  Try using the arrow keys or the numpad to move around in the game. How did that happen? BYOND provides quite a lot in the way of built-in game behavior for you. This can be a blessing in the case of MORPGs, roguelikes, and Graphical MUDS, but it's not exactly the best thing in the world if you want to do a lot of changing of the way things work to create an entirely different kind of game. Luckily, BYOND is a very flexible game engine, and allows you to change almost everything so long as you know what you are doing. Congratulations! You now have the rudiments of a game! Sure, the framerate is super low, the graphics are all stretched wrong, the character moves in really jumpy ways, and the UI is really inconvenient, but it is one hell of a start for just a few minute crash course in making games!

  In chapter two we are going to fix all of the complaints that I just listed as well as expand on our little walkable world by adding more stuff to it. We're also going to cover some really important concepts of object oriented programming and we're going to implement a temporary UI that will help us develop playable content insanely fast! Stay tuned!
Great Tutorial, I just wanted to know if this would be a weekly thing or whenever you have time thing.
Trying for a mix of the two.