GMS 2.3+ Decimal point path speed not working?

Ham

Member
I'm making a train game with a randomly generated looping train track, along it there is a train object that uses path finding to loop the tracks. It was relatively easy to set up, but at some point, I decided to set my path speed to 1.5, since 1 was too slow and 2 was too fast for me to do other stuff in the game. But something happened when I set the path speed to 1, sometimes, almost as if randomly, the train obj would reach it's destination, and then the path position, instead of going to 1, just stays at 0.75 or something like 0.67.

Sometimes it happens and sometimes it doesn't, and since my code is dependent on the path position variable, it affects my code alot.

Why is this happening?

P.S I'm not for sure what I need to provide, so just ask me for anything (screenshots, code, video) and I'll provide them. Thanks in advance to all responses
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Hello! Decimal path speeds are perfectly fine to use and I use them all the time in my current WIP. SO if something isn't working it would suggest an issue with the code you have that is dealing with the object(s) and the path(s). However, to solve the issue we really need to know more about the code you have for it. How are you detecting that the instance reaches the end of the path? That's probably the most important bit of code to show, although anything else that may be relevant would help too, like how you're generating the path and how the path-finding is set up, etc...
 

Ham

Member
Hello! Decimal path speeds are perfectly fine to use and I use them all the time in my current WIP. SO if something isn't working it would suggest an issue with the code you have that is dealing with the object(s) and the path(s). However, to solve the issue we really need to know more about the code you have for it. How are you detecting that the instance reaches the end of the path? That's probably the most important bit of code to show, although anything else that may be relevant would help too, like how you're generating the path and how the path-finding is set up, etc...
GML:
switch(game_state){
    case train.prep:
    text_state = "prep"
    supply_runner = 0;
    oSupplyArea.yield_rate = 180;
    break;
    case train.drop_off:
    last_pos_count--;
    if(last_pos_count<=0){
        last_pos_count = 5;
        last_pos = [x,y];
    }
    text_state = "drop off"
    if(mp_grid_path(tg.track_path_grid,track_path,x,y,tg.supply_pos[0],tg.supply_pos[1],false)){
        path_start(track_path,run_speed,path_action_continue,0);
    }
    if(path_position>=0.75){
        mp_grid_add_rectangle(tg.track_path_grid,0,0,room_width,room_height);
        for(var _x=tg.midx;_x<tg.grid_width;_x++){
            for(var _y=0;_y<tg.grid_height;_y++){
                if(tg.track_grid[# _x,_y]){
                    mp_grid_clear_cell(tg.track_path_grid,_x,_y)
                }
            }
        }
        game_state = train.dropping;
    }
    break;
    case train.dropping:
    text_state = "dropping";
    if(supply_runner!=0){
        wait_timer--;
        if(wait_timer<=0){
            wait_timer = 120;
            game_state = train.roundabout;
        }
    }
    break;
    case train.roundabout:
    last_pos_count--;
    if(last_pos_count<=0){
        last_pos_count = 5;
        last_pos = [x,y];
    }
    text_state = "roundabout"
    if(state){
        if(mp_grid_path(tg.track_path_grid,track_path,x,y,tg.base_pos[0],tg.base_pos[1],false)){
            path_start(track_path,run_speed,path_action_stop,0);
        }
    }else{
        if(mp_grid_path(tg.track_path_grid,track_path,x,y,tg.supply_pos[0],tg.supply_pos[1],false)){
            path_start(track_path,run_speed,path_action_stop,0);
        }
    }

    if(path_position>=0.75){
        state = !state;
        if(state){//going to base camp
            //cover right
            mp_grid_add_rectangle(tg.track_path_grid,tg.midx*16,0,room_width,room_height);
            for(var _x=0;_x<tg.midx+1;_x++){
                for(var _y=0;_y<tg.grid_height;_y++){
                    if(tg.track_grid[# _x,_y]){
                        mp_grid_clear_cell(tg.track_path_grid,_x,_y)
                    }
                }
            }
            roundabout_passes++;
            if(roundabout_passes==2){
                roundabout_passes = 0;
                state = 0;
                game_state = train.picking;
            }
        }else{//going to supply area
            //cover left
            mp_grid_add_rectangle(tg.track_path_grid,(tg.midx+1)*16,0,0,room_height);
            for(var _x=tg.midx;_x<tg.grid_width;_x++){
                for(var _y=0;_y<tg.grid_height;_y++){
                    if(tg.track_grid[# _x,_y]){
                        mp_grid_clear_cell(tg.track_path_grid,_x,_y)
                    }
                }
            }
            
        }
    }
    break;
    case train.picking:
    text_state = "picking"
    wait_timer--;
    if(wait_timer<=0){
        wait_timer = 120;
        game_state = train.final_trip;
        for(var i=0;i<4;i++){
            oBaseCamp.resource_values[|i] = clamp(oBaseCamp.resource_values[|i]+oSupplyArea.yield[|i],0,10)
        }
    }
    break;
    case train.final_trip:
    last_pos_count--;
    if(last_pos_count<=0){
        last_pos_count = 5;
        last_pos = [x,y];
    }
    text_state = "final_trip";
    if(mp_grid_path(tg.track_path_grid,track_path,x,y,tg.base_pos[0],tg.base_pos[1],false)){
        path_start(track_path,run_speed,path_action_stop,0);
    }
    if(path_position>=0.75){
        mp_grid_add_rectangle(tg.track_path_grid,(tg.midx+1)*16,0,0,room_height);
        for(var _x=tg.midx;_x<tg.grid_width;_x++){
            for(var _y=0;_y<tg.grid_height;_y++){
                if(tg.track_grid[# _x,_y]){
                    mp_grid_clear_cell(tg.track_path_grid,_x,_y)
                }
            }
        }
        game_state = train.prep;
        oBaseCamp.runs++;
    }
    break;
}
this is the code that makes my train loop around the track
 
Top