Basics of Coding for Archaeology: Scripts and Text

Before reading this post, please look at my previous post. Seriously, it will mean nothing to you otherwise. Yesterday I went through the basic layout of Game Maker, and explained the difference between rooms, sprites and objects, as well as basic commands using events and actions. Today we will expand this last concept and look at how we can display prewritten text on the screen. The main aim of this series of post is to give an overview of how we can use gaming software to create programs that can help archaeology.

As we saw last time we could easily write some text on the screen by using a series of action drop boxes that game maker has prepared for us, and in some cases this is an efficient and easy approach. But I’ve found that when making a more complex program you can go insane with the number of action drop boxes you would have to use. Hence I like to use Game Maker Language to tell the program exactly what want it to do.

The first step is to create a new object. We can ignore sprites (the visual component) this time as the object is not going to be visible on screen. We can then rename the object something like text_ctrl. This object will have a series of commands attached to it that it will follow at a certain point we decide, the event. In this case the event is going to be the “Draw” event, which means the action happens at all times. The “Draw” event is like the Step event I mentioned yesterday, but the former is connected with making things appear on the screen, so anything visual usually ends up in this event. If for example we are deciding how an object moves, then the step event is more appropriate, while creating a rectangle with certain dimensions is in the realm of the Draw event.

Image

Having decided when the action happens (all times) we then go to the “control” panel and choose the “execute script” action. This is where the coding happens, and where it all gets complicated yet interesting. Copy and paste the following:

{

draw_text(50,60,“Archaeology is pretty much the best thing ever.”);

//draws the text at position, creating new line when reached position

}

Save the object and then create a room in which add the object, which will appear as a blue ball with a question mark. Then run the game (green arrow) and hopefully you should get a screen that displays the message.

Image

What you are doing is running a script. You are telling the program to draw a piece of text, using what is called a function (draw_text), and you are giving it some parameters to follow. First of all, you are telling it where the text goes. The rooms are divided up by a grid, each point of which is recognisable by an x and a y. The point in the top left corner has an x of 0 and a y of 0, while all other points on the screen have an x and a y depending on where they are. The further down they are on the page, the more the y is going to increase, and the further across the point is, the higher the value of x. In this case we have told the program that we want the text to be at the point x=50 and y=60.

We then told it what we want to say, using a “string”, which you can recognise because they are within the “ ”. Within the “ “s you can write whatever you want, and use whatever symbols you want, without making any difference to the code itself. Outside them any small change can really create problems with the code.

A few more things to notice. I’ve used the brackets { and } to open and close a part of text I want to be separate from other parts of text. This means it will work as a block, and if many functions are within it they too form a block. At the moment they seem pointless, but they will become more and more important. Also, the ; closes a function, making space for another, while the ( and ) brackets are used to specify the parameters of the function. Finally the // and everything that follows is a comment, a way for me to put a note to myself to know what is going on. The program recognises the //s and ignores anything that follows on the same line.

A last piece of code is a slightly extended version of the one before:

{

draw_text_ext(50,60,”Archaeology is pretty much the best thing ever, except for making origami, because at least origami doesn’t pretend it has an edge that is nowhere near where you expect it, meaning you spend three days looking for something you thought would take you two minutes to find.”,-1,150);

//draws the text at position, creating new line when reached position

}

The function here is draw_text_ext() and it allows a few more things to take place. First of all It sets a limit to the line you are writing, in this case x=150. When the code gets to that point it automatically creates a new line underneath, at a distance specified by the -1 (which for some reason is the standard number to use). This way you can write long pieces of code without running out of the screen.

Image

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s