SOLVED "Visited X times" in text adventure

Lowang

Member
Hi guys,

I can´t wrap my head around, what seems to be a very simple problem.

I want a variable to rise by 1, every time I visit a "location" in my ds_grid.
But a simple if-structure in the step event would raise it every step, as long as the condition is met.

I can get it to rise once, and once only but how would I achieve a stat tracker, every time I visit a location.

Currently I fiddle around with a ds_grid like so:


GML:
//Create event

my_map = ds_grid_create(3,3);

ds_grid_add(my_map, 0,0,"Forest");

ds_grid_add(my_map, 1,0, "Village");

ds_grid_add(my_map, 2,0, "Forest_2");


ds_grid_add(my_map, 0,1, "Cave");

ds_grid_add(my_map, 1,1, "Castle");

ds_grid_add(my_map, 2,1, "Desert");


ds_grid_add(my_map, 0,2, "Chasm");

ds_grid_add(my_map, 1,2, "Camp");

ds_grid_add(my_map, 2,2, "River");

xx = 0;

yy = 0;


//step event

if keyboard_check_pressed(ord("D"))

        {

               action_text = "You walk East...";

               xx = xx + 1;

        }
Thanks in advance, and sorry for what seems to be a day-1 problem 8)
 

NightFrost

Member
Note that if you lock your locations to a grid, all your locations everywhere are equidistant from their neighbors, with all sharing the same distance, and you cannot change that. For example, you cannot describe a mountain by having three "foot of the mountain" rooms side-by-side in north, east, south and west each, plus a single room in the center to describe the summit. Nor can you have multiple paths between two locations that vary in length (ie one path is two rooms in east-west movement but the other is seven).

The better way to go about it would be to describe each room as self-contained data, and each room describes which other rooms its directions connect to. I have given a minimum example in this post.
 

Lowang

Member
Sorry, was a bit unclear.
I toggle the rooms via switch statement, and get the "map" with ds_grid_get.
But, unless im mistaken, the switch statement is being repeated?
So a "Visited ++" variable simply keeps adding.


Code:
switch location.place

{


case "Cave":

    scr_cave()  // just traing to get more order in there with scripts

    break;

    

case "Forest":

    loc_descript = "So much wood!"

    mov_allowed =

    {

        n : 0,

        e : 1,

        w : 0,

        s : 1       

    }

forest_visited ++;  // this keeps adding upwards

    break;
 
Last edited:

Lowang

Member
Note that if you lock your locations to a grid, all your locations everywhere are equidistant from their neighbors, with all sharing the same distance, and you cannot change that. For example, you cannot describe a mountain by having three "foot of the mountain" rooms side-by-side in north, east, south and west each, plus a single room in the center to describe the summit. Nor can you have multiple paths between two locations that vary in length (ie one path is two rooms in east-west movement but the other is seven).

The better way to go about it would be to describe each room as self-contained data, and each room describes which other rooms its directions connect to. I have given a minimum example in this post.
Yeah, I incorproated that, thanks :)
But probably in a round-about way.
I use structs to close ways:

GML:
mov_allowed =
    {
        n : 1,
        e : 1,
        w : 0,
        s : 1       
    }
And the input is preceded by a "If mov_allowed = 1" statement.
But thanks for the annotation in any way. I realize, that my code is proably was more complicated and confusing than it has any right to be, but I´m trying to force myself to complete the project to learn, errors and all...
 

chamaeleon

Member
Why don't you just make the move counter a member variable of the struct for each location and just increment it based on getting a struct out using xx and yy?
 

Lowang

Member
Why don't you just make the move counter a member variable of the struct for each location and just increment it based on getting a struct out using xx and yy?
Sounds good so far.
But I don´t think I quite get the second part.

So when I create a condition for, say, xx and yy being 2 and 2, would´nt it still keep counting as long as this is true?

Think I´m still not quite in the right mind set, so the questions might be a bit on the stupid side...
 

chamaeleon

Member
Sounds good so far.
But I don´t think I quite get the second part.

So when I create a condition for, say, xx and yy being 2 and 2, would´nt it still keep counting as long as this is true?
Well, it should only update the counter when you are actually adding or subtracting to xx and yy, not every step. If your original if expression does what you need, just add that update to it.
GML:
if keyboard_check_pressed(ord("D")) {
    action_text = "You walk East...";
    xx = xx + 1;
    my_map[# xx, yy].visited++;
}
Checking that xx and yy are not out of bounds left as an exercise. :)

Forgot to explicitly say that the stored value in each gird cell would then be a struct, containing your original string, as well as a visited variable initialized to 0, instead of only a string. Or have another ds_map, or whatever strikes your fancy if you don't want to mess with my_map.
 

Nidoking

Member
So when I create a condition for, say, xx and yy being 2 and 2, would´nt it still keep counting as long as this is true?
Why are you telling it to do that? If you put it in a Step event, it happens every step. That is what a Step event does. What I'm trying to tell you, what we're all trying to tell you, is that if you don't want it to happen every step, you don't put it in a Step event.

How often do you move to a new location? Do you do that every step, or only sometimes? What is it that causes you to move to a new location? How does that happen? Why does that happen? Don't answer to me - the answer is where your code for changing locations is. Yes? That is the stuff that happens when you change locations. So... if there is a thing that you want to happen only when you change locations, which is what you say you want... you put it there.
 

Lowang

Member
Thanks guys, that is basically it....
Duh, feel so dumb, of course the step event was the problem in the end.

Connecting it to the movement is the answer.
Don´t know why I was so blind in that regard,
thanks for sitting through that mess :)
 
Top