• 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!

GameMaker Moving from square to square

Status
Not open for further replies.
H

HanPrust

Guest
Dear gamemakers,

I am an old teacher and new to GMS and GML. Am trying to build a game using a board with squares to be used in class as a teaching aid. Players move based on dice throws, counting out the squares as they go. I managed to land in the right square, but I would like the player to jump to each following square until it reaches the number indicated by the dice.
I use a combination of D&D and simple code.

Help would be hugely appreciated. Thank you for reading this, and any advice you may be able to give.
 
H

HanPrust

Guest
Dear RefresherTowel,

Thanks for the speedy reply.

I just started the whole project from scratch and can't really show you much. I tried to recreate what I had in a "fresh" project but I am getting strange error messages now.
What I did was roll the dice with an irandom_range(1,6)
I add the value to the square number I retrieve from a csv file together with the coordinates of the new position (square number, x, y)
I am trying to build a loop that will retrieve the next square and move the pawn until the number of the die is reached.
Yesterday I got as far as moving the required number of squares but in a straight line. What I would like is move one square at a time, preferrably with a bit of a hop.

This is what I have in the pawn's step event (dobbelsteen means die):

if (global.dobbelsteen) > 0
{
global.map=global.map+1;
global.xx=ds_grid_get(global.map,1,global.map);
global.yy=ds_grid_get(global.map,2,global.map);


if point_distance(x, y, global.xx, global.yy) > 2
{
move_towards_point( global.xx, global.yy, 3);
}
else
{
speed=0;
}
global.dobbelsteen=global.dobbelsteen-1;
}

but now the system is telling me (although I checked) that global.map does not exist.
So, I can't even check if this code works.
 

NightFrost

Member
Do the squares just form a path, without any branches? You could use a DS list or an array to store it too in that case, where each list entry contains a x/y coordinate pair for the square's centerpoint. The square's ordered number is then just the data structure index; for example the 1st square in line is entry zero, second square is entry one, and so on. Each pawn would then know its currentsquare as an integer value. When they roll the dice, they know they must loop from current plus one to current plus dice roll in turn to read target positions. They'd have to track what is current target square and move towards it, and on reaching it switch to next, until last target has been reached.
 
H

HanPrust

Guest
Thanks NightFrost,

That's what I have been trying. Loading the csv into a ds_grid. In the 1st version it worked to the point where I reached the destination in one straight line, but no squares in between. It is one path with odd corners.
In the 2nd version GMS2 tells me the data structure does not exist (although I checked and even put it in the pawn object Create event).
 

NightFrost

Member
The pawns don't each need their own copy of the list. Just declare it as a global variable in some other object, optimally before the main game has started. In pawns, then, the only interaction with global squares map is when they read positions from it. The target x/y variables don't need to be global as in your sample code, as each pawn has to track their own targets (assuming there's more than one on the board). Are you familiar with the programming concept of finite state machines? It should be helpful here, sectioning your pawn code into logical groups that only run when required. I can see at least three states for the pawn: idle state where it does nothing, dice roll state where new dice value is generated, and movement state where it heads for given square.
 

TheouAegis

Member
global.xx=ds_grid_get(global.map,1,global.map);
Your grid ID is your row pointer as well. By the sounds of it, the error you are getting is that you only have 1 grid, but since you keep increasing global.map with each dice roll, GM expects tons of grids. OR, you have tons of grids, but they only have 1 or 2 rows, so global.map ends up pointing to a row that doesn't exist.
 
H

HanPrust

Guest
Thank you NightFrost,
The first bit I more or less worked out, but without the global variables I kept gettinig error messages.
I will certainly look into this finite state thing. I am not familiar with it.
 
H

HanPrust

Guest
Your grid ID is your row pointer as well. By the sounds of it, the error you are getting is that you only have 1 grid, but since you keep increasing global.map with each dice roll, GM expects tons of grids. OR, you have tons of grids, but they only have 1 or 2 rows, so global.map ends up pointing to a row that doesn't exist.
Simple but stupid mistake!. Thank you for pointing it out. I have been looking at this too long I think. Don't even see my own mistakes anymore.
 
Dear gamemakers,

I am an old teacher and new to GMS and GML. Am trying to build a game using a board with squares to be used in class as a teaching aid. Players move based on dice throws, counting out the squares as they go. I managed to land in the right square, but I would like the player to jump to each following square until it reaches the number indicated by the dice.
I use a combination of D&D and simple code.

Help would be hugely appreciated. Thank you for reading this, and any advice you may be able to give.
Have you completed your game? Is there a playable version of it?
 

Evanski

Raccoon Lord
Forum Staff
Moderator
Have you completed your game? Is there a playable version of it?
Seeing as the OP's account is deleted, I doubt you will get an answer

In the future please PM the user rather then bumping old topics

Speaking of.

As this topic is 3 years old and the OP's account is delete this topic is now locked
 
Status
Not open for further replies.
Top