• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Is there a tutorial available for a text based game?

I

iSolo

Guest
Hello everyone,

I understand that for a first project, it is a good practice to keep it simple. I believe that excluding pretty much anything graphical other than a text box and a very simple UI is a pretty good idea for a first game.
A good example for the type of game I would like to build is Zork. I have a bit of a different vision, I would like to have a background of whatever is happening in the game, just an image. So, if the player is in a forest, have a forest appear, if a player is in a cave, have a cave appear as the next screen. Just to make it a little more immersive.

Here's an example of the type of idea I have: YouTube link to Text Based GML Tutorial

Is there any Drag and Drop tutorial for this?
 
Last edited by a moderator:

flyinian

Member
Hello everyone,

I understand that for a first project, it is a good practice to keep it simple. I believe that excluding pretty much anything graphical other than a text box and a very simple UI is a pretty good idea for a first game.
A good example for the type of game I would like to build is Zork. I have a bit of a different vision, I would like to have a background of whatever is happening in the game, just an image. So, if the player is in a forest, have a forest appear, if a player is in a cave, have a cave appear as the next screen. Just to make it a little more immersive.

Here's an example of the type of idea I have: YouTube link to Text Based GML Tutorial

Is there any Drag and Drop tutorial for this?
For DnD? Probably not. There aren't many tutorials for DnD.

Most people highly recommend switching to gml asap since its better to learn the language directly and there are more tutorials for gml.
 

Rob

Member
Totally not drag 'n drop, but here's how to do it in GML

if you have a grid like this:

GML:
0 0 1 0 1
0 1 1 0 2
1 1 2 0 0
0 0 0 0 0
0 0 0 0 0
Where 0 is plains, 1 is trees, and 2 are mountains, it would look like this, with ascii representations this time, instead of numbers

Code:
_ _ * _ *
_ * * _ ^
* * ^ _ _
_ _ _ _ _
_ _ _ _ _
The grid would just hold numbers, and you could have ONE sprite, with each number being an image_index that you want to draw on the screen.
The first image_index would be plains, the second trees, and the third mountains, for example.

You would have 2 variables, which track where you are in the grid; grid_x and grid_y. Pressing up/down would change grid_y, left/right changes grid_x.

Whatever value that's stored in the cell you're in, that's the image_index you'd draw. global.grid[# 1, 1] has a value of "1" so Trees would be drawn, for example.

How to code it?

We need to put values into the grid, and we can either import a .csv file or just type everything into the create event. The second option is lengthier but
simpler to understand visually so here goes:


Code:
Make a sprite called spr_terrain, and make 3 images, 1 for plains, 1 for trees, 1 for mountains. Leave the sprite origin point in the top left.

Make an object called obj_grid
Code:
//Create Event of obj_grid

global.grid = ds_grid_create(5, 5); //Creates a 5x5 grid

grid_x = 0;
grid_y = 0;
Code:
//Create event of obj_grid - underneath what we just coded

//When a grid is created, the values will already be set to 0, so we just modify the other cells
global.grid[# 0, 2] = "1";
global.grid[# 0, 4] = "1";
global.grid[# 1, 1] = "1";
global.grid[# 1, 2] = "1";
global.grid[# 1, 4] = "2";
global.grid[# 2, 0] = "1";
global.grid[# 2, 1] = "1";
global.grid[# 2, 2] = "2";
Changing values in a grid like this is laborious and there are better ways, but I think this is the simplest to understand, like I said.

It's worth noting that the values stored in the grid are strings, not integers/reals (they look the same to us but they are treated differently), but gamemaker will convert them into numbers for us anyway so we don't need to convert them ourselves.
Keeping the values as strings is useful (for reasons you may find out in the future if you stick with it) and takes us less time to set up.


Code:
//Draw event of obj_grid

//Which image_index is stored in the grid position that we're in?
var index_to_draw = global.grid[# grid_x, grid_y];

//Draw the image_index of our terrain sprite from the top left corner of the screen
draw_sprite(spr_terrain, index_to_draw, 0, 0);

Now all we need to do is allow the player to move around by pressing up/down/left/right

Code:
//step event of obj_grid

if (keyboard_check_pressed(vk_left) ) grid_x --; //This is the same as typing "grid_x = grid_x - 1;" or "grid_x -= 1" but faster
if (keyboard_check_pressed(vk_right) ) grid_x ++;
if (keyboard_check_pressed(vk_up) ) grid_y --;
if (keyboard_check_pressed(vk_down) ) grid_y ++;

//we don't want grid_x or grid_y to go OUTSIDE the boundaries of the grid eg values of -1 or 5 would be outside of the grid (valid values are 0 - 4 for our grid of 5x5)

//We can use a useful function called "clamp" to make sure our values stay within our boundaries

var min_grid_x = 0;
var min_grid_y = 0;
var max_grid_x = ds_grid_width(global.grid) - 1;
var max_grid_y = ds_grid_height(global.grid) - 1;


grid_x = clamp(grid_x, min_grid_x, max_grid_x);
grid_y = clamp(grid_y, min_grid_y, max_grid_y);


And that's it for a simple "move around a grid and have a visual representation of where you are".

You can't do much more than move around but hopefully it helps ease you into GML. If you want to know more you can hit me up on discord Gamemaker Rob#1691

P.S. This doesn't cover a text box but there's more to a text box than you might think.
 
Last edited:
Top