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

Legacy GM Wall problem with Point and Click Adventure

A

AkjoHD

Guest
Hello, everybody.

I have a question in Game Maker Studio 1.4. I am still a beginner and need help with a Point and Click Adventure.


Right now I have:

a player who is controllable with Point and Click

a Pathfinder AI using a grid

a collectable object (still without functions and inventory)


Problem:

When I click on a wall in the game, the player is ported to 0, 0. He can then continue to run normally.


I would like to:


that the player stops on the spot when you click on a wall.

------------------------------------------------------------------------------------------------------------------------------------------------
Here are some codes:

Player Step:
Code:
mouseDistance = point_distance(x, y, obj_mouseClick.x, obj_mouseClick.y)
var grid = mp_grid_create(0, 0, room_width/32, room_height/32, 32, 32)
var path = path_add()
mp_grid_add_instances(path, obj_wall, 0)
mp_grid_path(grid, path, x, y, obj_mouseClick.x, obj_mouseClick.y, 1)
 path_start(path, min(4, mouseDistance), "", 1)

if instance_exists(obj_object)
{
    if collision_circle(obj_object.x, obj_object.y, 50, obj_player, false, false)
    {
        if global.mouseCheck = true
        {
            global.tookobject = true
            with(obj_objectinfo)
            {
                instance_destroy()
            }
            with(obj_object)
            {
                instance_destroy()
            }
        }
    }
}

if position_meeting(mouse_x, mouse_y, obj_wall) && mouse_check_button_released(mb_left)
{
    x = obj_player.x
    y = obj_player.y
}
Object Step:
Code:
if position_meeting(mouse_x, mouse_y, obj_object)
{
    global.drawinfo = true
}

if !position_meeting(mouse_x, mouse_y, obj_object)
{
    global.drawinfo = false
 
}

if position_meeting(mouse_x, mouse_y, obj_object) && mouse_check_button_released(mb_left)
{
    global.mouseCheck = true
}

if !position_meeting(mouse_x, mouse_y, obj_object) && mouse_check_button_released(mb_left)
{
    global.mouseCheck = false
}
MouseClick Step:
Code:
if global.tookobject = true
{
     x = obj_player.x
     y = obj_player.y
     global.tookobject = false   
}
MouseClick GlobalLeftPressed
Code:
x = mouse_x
y = mouse_y
 

Simon Gust

Member
Code:
x = obj_player.x
y = obj_player.y
Are these intended?
Is the code you provided not inside obj_player?

What I read from the manual to end a path you can use
Code:
path_end();
 
A

AkjoHD

Guest
Code:
x = obj_player.x
y = obj_player.y
Are these intended?
Is the code you provided not inside obj_player?

What I read from the manual to end a path you can use
Code:
path_end();
1. My control works by placing the object MouseClick at the cursor position as soon as you press the left mouse button. The player then follows this object.

2. Yes, that's intended. So that the player stops as soon as the object has been picked up.

3. Why would I end the path. And how should that help with my problem?

Well... thanks for the help ;)
 

TheouAegis

Member
1. My control works by placing the object MouseClick at the cursor position as soon as you press the left mouse button. The player then follows this object.

2. Yes, that's intended. So that the player stops as soon as the object has been picked up.
He's talking about in the Player's Step code. You had this block:
Code:
if position_meeting(mouse_x, mouse_y, obj_wall) && mouse_check_button_released(mb_left)
{
   x = obj_player.x
   y = obj_player.y
}
That code is inside obj_player, so there's no point in putting obj_player.x/obj_player.y because that's just self-referential code. And then once you fixed that, you'd realize it just says
Code:
x = x;
y =  y;

var grid = mp_grid_create(0, 0, room_width/32, room_height/32, 32, 32);
var path = path_add();
Unless you left out a lot more code, you just created a huge memory leak here. You create a grid resource but don't destroy it in this code; likewise, you create a path resource and don't destroy it in this code. In either case, you shouldn't even be creating these resources in the Step Event. Create them both in the Game Start event, clear the grid in the Room Start event and repopulate it, and reuse the path instead of creating a new one in the Step event.


As for the (0,0) issue... No idea. Once on a path, changing the player's coordinates should make no difference, but on the off-chance it does, I'd suggest verifying in the debugger that there is only one single instance of obj_player in the room, or use draw_text(0,0,instance_number(obj_player)) in the GUI Event. Then again, removing that useless code I referred to at the top of this post would make this a moot point anyway.
 
Top