Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎲 GameMaker

GML Code crash when pathing (memory problem?)

Started by Bugman96 Aug 13, 2014 at 7:55 PM 1 replies 3.4k views
Original Post
Bugman96
Bugman96

Hi, I am new to the forum. I decided to come here because I'm not getting and replies at the yoyogames forum. On my game on Gamemaker Pro, if you spam right click (which creates a path) the game will crash. Here's my code for the player object under "glob right press" event which creates the path etc:


if(instance_exists(target_obj)) {
    with (target_obj) instance_destroy();
    path_clear_points(path); //using this code and the one below, I thought it would solve memory problems arrrggg...
    path_delete(path);
}

if(place_free(mouse_x,mouse_y)){
target = instance_create(mouse_x, mouse_y, target_obj);
}

if (instance_exists(target_obj)){
    path = path_add();
    mp_potential_path_object(path, target_obj.x, target_obj.y, 1, 100, wall_obj);
    path_start(path, 5, 0, 0);
    
    }

Anyone, any ideas? I'm really stuck... and it would be sad to abandon it cause I worked for so long. sad.png

DejaimeNeto
DejaimeNeto

Did you try adding a minimum delay for the order? Like only allowing the pathfinder to work, say, 10 times per second for each entity (as in add a 100 ms cooldown to it)?

I really do not know anything about GameMaker, nor even what language it uses. In other words, this is a complete shot in the dark here.

jbadams
jbadams

Moving you to our APIs and Tools forum. smile.png

dejaime's idea sounds like a good one. Basically, you want to check if the player has already created a path within x amount of time (I'd start with 500ms/half a second 200ms/5 times per second - test from there to see if you need a shorter or longer time for the game to feel responsive and to avoid the problem) and simply ignore the additional input if they already have -- this shouldn't make any difference to game play and should avoid a lot of unnecessary calculation if the player "spams" the right mouse button.

I do own a copy of Game Maker: Studio (it uses it's own language called GML for future reference dejaime) but haven't spent a lot of time experimenting with it, so I'm afraid I can't really offer a specific example either, but the basic idea should provide a good starting point. Let us know if you can't figure it out and if no one else chimes in I'll fire up GM:S and see if I can put together an example for you.

Hope that helps! smile.png

- Jason Astle-Adams

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.