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

GML object hitbox (when interacting by pressing Z) appears to be much larger than the sprite itself? [Thought the problem was fixed, help still needed]

So when I have an object on a map (using earthbound's item sprite as a placeholder for testing) and I go up to it and press Z, I do interact with it okay. However, what happens is, I can click on blank space surrounding the item and it treats it as if I'm interacting with the item? Now, I feel like it may be something to do with the player object itself, due to it not only happening with using this sprite as an object, but ANY objects I use?
1634775675907.png(example)
Create:
GML:
pid = 0
item = 0
image_speed = 0
alarm[0] = 1
b = 0
Alarm [0]
GML:
if ds_map_find_value(global.presents,pid) = 0 {
    image_index = 1
} else {
    image_index = 0
    item = ds_map_find_value(global.presents,pid)
}
Alarm 1
GML:
if instance_exists(objTextBox) {
    alarm[1] = 1
} else {
    if item = -1 {
        ds_map_replace(global.presents,pid,0)
        image_index = 1
    } else {
        var a;
        a = instance_create(0,0,objTextBox);
        a.strno = 0
        b = add_item_ext(item);
        if b = -1 {
            if global.pl_count = 1 {
                a.str[0] = "@ But "+global.s_name[1]+" was carrying too much stuff already."
            } else {
                a.str[0] = "@ But everyone was carrying too much stuff already."
            }
        } else {
            a.str[0] = "@ "+global.s_name[b+1]+" took it."
            ds_map_replace(global.presents,pid,0)
            image_index = 1
            audio_play_sound(snditemget1,0,0)
        }
    }
}
Alarm 11
GML:
event_user(0)
Draw
GML:
draw_self()
User Event 0
GML:
var a = instance_create(0,0,objTextBox);
if image_index != 1 {
    a.strno = 1;
    a.str[0] = "@ " + global.s_name[1] + " opened the present."
    if item = -1 {
        a.str[1] = "@ But it was empty."
    } else {
        a.str[1] = "@ Inside the present, there was "+global.item[item,17]+global.item[item,1]+"!"
    }
    audio_play_sound(sndpresent,0,0)
    alarm[1] = 1;
} else {
    a.strno = 0;
    a.str[0] = "@ It's empty."
}


Create
GML:
if instance_number(objPlayer) > 1 { instance_destroy(); exit }

dir = 270;
direction = dir

walk_speed = 2;
water_speed = 1;
run_speed = walk_speed;
canmove = 1;
water = 0;
ladder = 0;
can_splash = true;
stairs_ang = 0;
invincible = 0;
invertedcontrols = 0;
shadow = 1
player = 1
dx = 0
dy = 0
key_direction = 270;

for(var c = 0;c <= 5*100;c++){
    prevx[c] = x
    prevy[c] = y
    prevd[c] = direction
}


spr_walking[0,0] =    sprProtag_f_r
spr_walking[90,0] =   sprProtag_f_u
spr_walking[180,0] =  sprProtag_f_l
spr_walking[270,0] =  sprProtag_f_d
Step
GML:
/// @description Movement
depth = -y

// Handle keyboard input
dx = 0
dy = 0

if !global.s_strange[1] {
    dx = (keyboard_check(vk_right) xor round(joy_axis(objPersistent.device,0)) == 1) - (keyboard_check(vk_left) xor round(joy_axis(objPersistent.device,0)) == -1);
    dy = (keyboard_check(vk_down) xor round(joy_axis(objPersistent.device,1)) == 1) - (keyboard_check(vk_up) xor round(joy_axis(objPersistent.device,1)) == -1);
} else {
    switch invertedcontrols {
        case 0:
            dx = -(keyboard_check(vk_right) or round(joy_axis(objPersistent.device,0)) == 1) + (keyboard_check(vk_left) or round(joy_axis(objPersistent.device,0)) == -1);
            dy = -(keyboard_check(vk_down) or round(joy_axis(objPersistent.device,1)) == 1) + (keyboard_check(vk_up) or round(joy_axis(objPersistent.device,1)) == -1);
            break;
        case 1:
            dx = (keyboard_check(vk_right) or round(joy_axis(objPersistent.device,0)) == 1) - (keyboard_check(vk_left) or round(joy_axis(objPersistent.device,0)) == -1);
            dy = (keyboard_check(vk_down) or round(joy_axis(objPersistent.device,1)) == 1) - (keyboard_check(vk_up) or round(joy_axis(objPersistent.device,1)) == -1);
            break;
        case 2:
            dx = (keyboard_check(vk_down) or round(joy_axis(objPersistent.device,1)) == 1) - (keyboard_check(vk_up) or round(joy_axis(objPersistent.device,1)) == -1);
            dy = (keyboard_check(vk_right) or round(joy_axis(objPersistent.device,0)) == 1) - (keyboard_check(vk_left) or round(joy_axis(objPersistent.device,0)) == -1);
            break;
        case 3:
            dx = -(keyboard_check(vk_down) or round(joy_axis(objPersistent.device,1)) == 1) + (keyboard_check(vk_up) or round(joy_axis(objPersistent.device,1)) == -1);
            dy = -(keyboard_check(vk_right) or round(joy_axis(objPersistent.device,0)) == 1) + (keyboard_check(vk_left) or round(joy_axis(objPersistent.device,0)) == -1);
            break;
    }
}

if global.debug {
    objDebug.dx = dx
    objDebug.dy = dy
}

water = position_meeting(x,y,objWater)
ladder = position_meeting(x,y,objLadder)

if canmove = 1 {
    //if (dx > 0.5 or dx < -0.5) || (dy > 0.5 or dy < -0.5) {
    if (abs(dx) > 0.5) || (abs(dy) > 0.5) {
        // Walk
            key_direction = point_direction(0, 0, dx, dy);
            speed = (walk_speed-0.5*(water||ladder)-0.75*(global.s_numb[1] or global.s_numb[2] or global.s_numb[3] or global.s_numb[4]))
            
            if speed > 0 {
                if position_meeting(x,y,objStairs){
                    stairs_ang = -45*(abs(dx) > 0 and abs(dy) < 0.5 )
                } else if position_meeting(x,y,objStairs2) {
                    stairs_ang = 45*(abs(dx) > 0 and abs(dy) < 0.5 )
                } else {
                    stairs_ang = 0
                }
            } else {
                stairs_ang = 0
            }
            
            direction = key_direction+stairs_ang
            
            if water {
                if can_splash {
                    audio_play_sound(sndsplash,0,0)
                    alarm[2] = 30
                    can_splash = false
                }
            }
    } else {
        // Idle
        speed = 0
        image_index = 0
    }
}


if (direction >= 0 and direction < 45/2) or (direction >= 315+45/2 and direction < 360) {
    dir = 0-stairs_ang
} else if (direction >= 45+45/2 and direction < 90+45/2) {
    dir = 90-stairs_ang
} else if (direction >= 135+45/2 and direction < 180+45/2) {
    dir = 180-stairs_ang
} else if (direction >= 225+45/2 and direction < 270+45/2) {
    dir = 270-stairs_ang
}

if dir < 0 {
    dir = 360+dir
} else if dir = 360 {
    dir = 0
}

if !ladder {
    sprite_index = spr_walking[dir,global.dead[player]]
} else {
    sprite_index = spr_climbing[0]
}



/// Interaction with objects

audio_listener_position(x, y, 0);

if keyboard_check_pressed(global.kb_choose) and canmove and !instance_exists(obj_inv) and !instance_exists(objStorage)  {
    var npc, angle, box;
    if distance_to_object(objNPCExtender) < 12 {
        npc = instance_nearest(x,y,objNPCExtender).link
        angle = point_direction(x,y,npc.x,npc.y)
        if (angle < 360+(45/2)) and (angle > 360-(45/2))
        or (angle < 0+(45/2)) and (angle > 0-(45/2))  { direction = 0 }
        else if (angle < 90+(45/2)) and (angle > 90-(45/2)) { direction = 90  }
        else if (angle < 180+(45/2)) and (angle > 180-(45/2)) { direction = 180  }
        else if (angle < 270+(45/2)) and (angle > 270-(45/2)) { direction = 270  }
        speed = 0
        image_index = 0
        with npc { alarm[11] = 1 }
        exit
    }
    
    if distance_to_object(parDoor) < 8 {
        npc = instance_nearest(x,y,parDoor)
        if npc.visible {
            angle = point_direction(x,y,npc.x,npc.y)
            if (angle < 360+(45/2)) and (angle > 360-(45/2))
            or (angle < 0+(45/2)) and (angle > 0-(45/2))  { direction = 0 ; with npc { direction = 180 } }
            else if (angle < 90+(45/2)) and (angle > 90-(45/2)) { direction = 90 ; with npc { direction = 270 } }
            else if (angle < 180+(45/2)) and (angle > 180-(45/2)) { direction = 180 ; with npc { direction = 0 } }
            else if (angle < 270+(45/2)) and (angle > 270-(45/2)) { direction = 270 ; with npc { direction = 90 } }
        }
        with npc { alarm[11] = 1 }
        speed = 0
        image_index = 0
        exit
    }
    
    
    if distance_to_object(parNpc) < 12 {
        npc = instance_nearest(x,y,parNpc)
        if npc.visible {
            angle = point_direction(x,y,npc.x,npc.y)
            if (angle < 360+(45/2)) and (angle > 360-(45/2))
            or (angle < 0+(45/2)) and (angle > 0-(45/2))  { direction = 0 ; with npc { direction = 180 } }
            else if (angle < 90+(45/2)) and (angle > 90-(45/2)) { direction = 90 ; with npc { direction = 270 } }
            else if (angle < 180+(45/2)) and (angle > 180-(45/2)) { direction = 180 ; with npc { direction = 0 } }
            else if (angle < 270+(45/2)) and (angle > 270-(45/2)) { direction = 270 ; with npc { direction = 90 } } 
        }
        with npc { alarm[11] = 1 }
        speed = 0
        image_index = 0
        exit
    }
}

///Prolong invincibility if menu exists

if ie(parDeactivator) and invincible {
    alarm[3]++;
}
End Step
GML:
/// @description Bouncing off solids
if speed > 0 { image_speed = 0.15/(2*global.s_numb[1]+1)} else { image_speed = 0 }

collision_handle();

///Handling party movement
var more;
more = 1 // This adds an additional gap between party members. 1 by default, don't set it to zero!

if(hspeed != 0 or vspeed != 0){
    for(var c = 5*10*more;c > 0;c -= 1){
        prevx[c] = prevx[c - 1]
        prevy[c] = prevy[c - 1]
        prevd[c] = prevd[c - 1]
    }
    prevx[0] = x
    prevy[0] = y
    prevd[0] = direction
}

//Party members' direction handle and position update
with(objPartyCharacter){
    x = other.prevx[player_index*10*more]
    y = other.prevy[player_index*10*more]
    direction = other.prevd[player_index*10*more]
    if !(direction = 0 or direction = 90 or direction = 180 or direction = 270) and player_index > 1 {
        x = floor(x)
        y = floor(y)
    }
}

///Views
if !global.cutscene or get_flag(28) {
    __view_set( e__VW.XView, 0, min(max(x-__view_get( e__VW.WView, 0 )/2,0),room_width-__view_get( e__VW.WView, 0 )) );
    __view_set( e__VW.YView, 0, min(max(y-__view_get( e__VW.HView, 0 )/2,0),room_height-__view_get( e__VW.HView, 0 )) );
    __view_set( e__VW.XView, 0, round(__view_get( e__VW.XView, 0 )) )
    __view_set( e__VW.YView, 0, round(__view_get( e__VW.YView, 0 )) )
}
Alarm 11
GML:
speed = 0
Draw
GML:
if !water {
    if shadow { draw_sprite(sprShadow,0,x,y) }
    draw_sprite_ext(sprite_index,image_index,x,y,image_xscale,image_yscale,image_angle,image_blend,image_alpha)
} else {
    draw_sprite_part_ext(sprite_index,image_index,0,0,sprite_width,2*sprite_height/3,x-sprite_width/2,y-16,image_xscale,image_yscale,image_blend,image_alpha)
    draw_sprite(sprWaterRipple,image_index,x,y)
}
Room Start
GML:
/// @description  Move the player to saved position
if global.thex > 0 and global.they > 0 and room != rmGameOver {
    x = global.thex
    y = global.they
    direction = global.thedir
}

event_user(0)

///Event stuff

///Views

__view_set( e__VW.XView, 0, round(__view_get( e__VW.XView, 0 )) )
__view_set( e__VW.YView, 0, round(__view_get( e__VW.YView, 0 )) )

if !global.cutscene or get_flag(28) {
    __view_set( e__VW.XView, 0, min(max(x-__view_get( e__VW.WView, 0 )/2,0),room_width-__view_get( e__VW.WView, 0 )) );
    __view_set( e__VW.YView, 0, min(max(y-__view_get( e__VW.HView, 0 )/2,0),room_height-__view_get( e__VW.HView, 0 )) );
    __view_set( e__VW.XView, 0, round(__view_get( e__VW.XView, 0 )) )
    __view_set( e__VW.YView, 0, round(__view_get( e__VW.YView, 0 )) )
}
User Event 0
GML:
/// @description Check whether to trigger invincibility
if ie(objOwEnemyBlink) and !invincible {
    invincible = 1
    alarm[3] = 120 // 2 seconds
    alarm[4] = 10
}

///Make allies that follow you around
for(var c = 0;c <= 5*14;c++){
    prevx[c] = x
    prevy[c] = y
    prevd[c] = direction
}

if room != rmGameOver {
    if(!instance_exists(objPartyCharacter)){
        for(c = 1;c < global.pl_count;c += 1){
            var partyCharacter = instance_create(x,y,objPartyCharacter);
            partyCharacter.player_index = c
            with(partyCharacter){
                x = objPlayer.prevx[0]; y = objPlayer.prevy[0];
                switch player_index {
                    default:
                        spr_walking[0,0] =    sprProtag_f_r
                        spr_walking[90,0] =   sprProtag_f_u
                        spr_walking[180,0] =  sprProtag_f_l
                        spr_walking[270,0] =  sprProtag_f_d
                        break;
                }
            }
        }
    }
}
 

Nidoking

Member
It looks like you're using distance_to_object to determine whether there's an interactable instance or not. So it's only checking how far you are from it, not what direction you're facing or whether there's any contact.
 
It looks like you're using distance_to_object to determine whether there's an interactable instance or not. So it's only checking how far you are from it, not what direction you're facing or whether there's any contact.
I have played around with that quite a bit, and while I can reduce the "hitbox" around the object and make it more manageable, if I have two objects close to one another, it only picks up on one's dialog
 

Nidoking

Member
Well, the solution is probably not to use distance_to_object if you're concerned about direction as well. Something more like instance_place or instance_position is more standard for what you're probably trying to do.
 
Well, the solution is probably not to use distance_to_object if you're concerned about direction as well. Something more like instance_place or instance_position is more standard for what you're probably trying to do.
Awesome, I'll give that a try right now. Thank you so much for the kind advice.
 
Well, the solution is probably not to use distance_to_object if you're concerned about direction as well. Something more like instance_place or instance_position is more standard for what you're probably trying to do.
Sorry for bringing this thread back up.

I've messed around a bit with the code in STEP, and it seems to have been counter-productive, as now selecting ANY blank space in the room causes the textbox for one object to show up.

Updated code:
GML:
/// @description Movement
depth = -y

// Handle keyboard input
dx = 0
dy = 0

if !global.s_strange[1] {
    dx = (keyboard_check(vk_right) xor round(joy_axis(objPersistent.device,0)) == 1) - (keyboard_check(vk_left) xor round(joy_axis(objPersistent.device,0)) == -1);
    dy = (keyboard_check(vk_down) xor round(joy_axis(objPersistent.device,1)) == 1) - (keyboard_check(vk_up) xor round(joy_axis(objPersistent.device,1)) == -1);
} else {
    switch invertedcontrols {
        case 0:
            dx = -(keyboard_check(vk_right) or round(joy_axis(objPersistent.device,0)) == 1) + (keyboard_check(vk_left) or round(joy_axis(objPersistent.device,0)) == -1);
            dy = -(keyboard_check(vk_down) or round(joy_axis(objPersistent.device,1)) == 1) + (keyboard_check(vk_up) or round(joy_axis(objPersistent.device,1)) == -1);
            break;
        case 1:
            dx = (keyboard_check(vk_right) or round(joy_axis(objPersistent.device,0)) == 1) - (keyboard_check(vk_left) or round(joy_axis(objPersistent.device,0)) == -1);
            dy = (keyboard_check(vk_down) or round(joy_axis(objPersistent.device,1)) == 1) - (keyboard_check(vk_up) or round(joy_axis(objPersistent.device,1)) == -1);
            break;
        case 2:
            dx = (keyboard_check(vk_down) or round(joy_axis(objPersistent.device,1)) == 1) - (keyboard_check(vk_up) or round(joy_axis(objPersistent.device,1)) == -1);
            dy = (keyboard_check(vk_right) or round(joy_axis(objPersistent.device,0)) == 1) - (keyboard_check(vk_left) or round(joy_axis(objPersistent.device,0)) == -1);
            break;
        case 3:
            dx = -(keyboard_check(vk_down) or round(joy_axis(objPersistent.device,1)) == 1) + (keyboard_check(vk_up) or round(joy_axis(objPersistent.device,1)) == -1);
            dy = -(keyboard_check(vk_right) or round(joy_axis(objPersistent.device,0)) == 1) + (keyboard_check(vk_left) or round(joy_axis(objPersistent.device,0)) == -1);
            break;
    }
}

if global.debug {
    objDebug.dx = dx
    objDebug.dy = dy
}

water = position_meeting(x,y,objWater)
ladder = position_meeting(x,y,objLadder)

if canmove = 1 {
    //if (dx > 0.5 or dx < -0.5) || (dy > 0.5 or dy < -0.5) {
    if (abs(dx) > 0.5) || (abs(dy) > 0.5) {
        // Walk
            key_direction = point_direction(0, 0, dx, dy);
            speed = (walk_speed-0.5*(water||ladder)-0.75*(global.s_numb[1] or global.s_numb[2] or global.s_numb[3] or global.s_numb[4]))
            
            if speed > 0 {
                if position_meeting(x,y,objStairs){
                    stairs_ang = -45*(abs(dx) > 0 and abs(dy) < 0.5 )
                } else if position_meeting(x,y,objStairs2) {
                    stairs_ang = 45*(abs(dx) > 0 and abs(dy) < 0.5 )
                } else {
                    stairs_ang = 0
                }
            } else {
                stairs_ang = 0
            }
            
            direction = key_direction+stairs_ang
            
            if water {
                if can_splash {
                    audio_play_sound(sndsplash,0,0)
                    alarm[2] = 30
                    can_splash = false
                }
            }
    } else {
        // Idle
        speed = 0
        image_index = 0
    }
}


if (direction >= 0 and direction < 45/2) or (direction >= 315+45/2 and direction < 360) {
    dir = 0-stairs_ang
} else if (direction >= 45+45/2 and direction < 90+45/2) {
    dir = 90-stairs_ang
} else if (direction >= 135+45/2 and direction < 180+45/2) {
    dir = 180-stairs_ang
} else if (direction >= 225+45/2 and direction < 270+45/2) {
    dir = 270-stairs_ang
}

if dir < 0 {
    dir = 360+dir
} else if dir = 360 {
    dir = 0
}

if !ladder {
    sprite_index = spr_walking[dir,global.dead[player]]
} else {
    sprite_index = spr_climbing[0]
}



/// Interaction with objects

audio_listener_position(x, y, 0);

if keyboard_check_pressed(global.kb_choose) and canmove and !instance_exists(obj_inv) and !instance_exists(objStorage)  {
    var npc, angle, box;
    if instance_place(x,y,parNpc) < 2 {
        npc = instance_nearest(x,y,parNpc)
        angle = point_direction(x,y,npc.x,npc.y)
        if (angle < 360) and (angle > 360)
        or (angle < 0) and (angle > 0)  { direction = 0 }
        else if (angle < 90) and (angle > 90) { direction = 90  }
        else if (angle < 180) and (angle > 180) { direction = 180  }
        else if (angle < 270) and (angle > 270) { direction = 270  }
        speed = 0
        image_index = 0
        with npc { alarm[11] = 1 }
        exit
    }
    
    if distance_to_object(parDoor) < 4 {
        npc = instance_nearest(x,y,parDoor)
        if npc.visible {
            angle = point_direction(x,y,npc.x,npc.y)
            if (angle < 360) and (angle > 360)
            or (angle < 0) and (angle > 0)  { direction = 0 ; with npc { direction = 180 } }
            else if (angle < 90) and (angle > 90) { direction = 90 ; with npc { direction = 270 } }
            else if (angle < 180) and (angle > 180) { direction = 180 ; with npc { direction = 0 } }
            else if (angle < 270) and (angle > 270) { direction = 270 ; with npc { direction = 90 } }
        }
        with npc { alarm[11] = 1 }
        speed = 0
        image_index = 0
        exit
    }
    
    
    if instance_place(x,y,parNpc) < 2 {
        npc = instance_nearest(x,y,parNpc)
        if npc.visible {
            angle = point_direction(x,y,npc.x,npc.y)
                        if (angle < 360) and (angle > 360)
            or (angle < 0) and (angle > 0)  { direction = 0 ; with npc { direction = 180 } }
            else if (angle < 90) and (angle > 90) { direction = 90 ; with npc { direction = 270 } }
            else if (angle < 180) and (angle > 180) { direction = 180 ; with npc { direction = 0 } }
            else if (angle < 270) and (angle > 270) { direction = 270 ; with npc { direction = 90 } }
        with npc { alarm[11] = 1 }
        speed = 0
        image_index = 0
        exit
    }
}

///Prolong invincibility if menu exists

if ie(parDeactivator) and invincible {
    alarm[3]++;
}

}
If somebody could help with how I'm doing this wrong, that would be much appreciated. I'm not necessarily new to GML, but it has been a while since I've dabbled it in.
 

TheouAegis

Member
Why are you using xor?

if instance_place(x,y,parNpc) < 2
instance_place() returns an instance id (greater than 1000000) or -4 if nothing is found. Since -4 is less than 2, this conditional will be true whenever you interact on empty space. And if you're going to be using instance_place(), there is almost no reason at all to use instance_nearest(). Even the one reason that's arguable is arguably trivial. Also, assuming you just got confused between < and >, there is no point in comparing against 2, because the value can never be anything other than -4 or a value greater than 1000000, thus even the boolean check of if instance_place(x,y,parNpc){, as improper as it is, will suffice.
 
Why are you using xor?



instance_place() returns an instance id (greater than 1000000) or -4 if nothing is found. Since -4 is less than 2, this conditional will be true whenever you interact on empty space. And if you're going to be using instance_place(), there is almost no reason at all to use instance_nearest(). Even the one reason that's arguable is arguably trivial. Also, assuming you just got confused between < and >, there is no point in comparing against 2, because the value can never be anything other than -4 or a value greater than 1000000, thus even the boolean check of if instance_place(x,y,parNpc){, as improper as it is, will suffice.
I'm using xor because it was what was recommended in a tutorial I was using for this specific interaction. Would there be something better to use?
 

TheouAegis

Member
Just seems to me like or would be more logical. xor is going to cancel input if the player happens to bump the joystick to the right while also holding right key, or bumping the joystick to the left while holding the left key.
 
Just seems to me like or would be more logical. xor is going to cancel input if the player happens to bump the joystick to the right while also holding right key, or bumping the joystick to the left while holding the left key.
Okay, makes sense. Thank you. I removed the instance id and removed instance nearest, (leaving the following code) and now nothing is really interactable.
GML:
    if instance_place(x,y,parNpc){
        if npc.visible {
            angle = point_direction(x,y,npc.x,npc.y)
                        if (angle = 360)
            or (angle = 0)  { direction = 0 ; with npc { direction = 180 } }
            else if (angle = 90) { direction = 90 ; with npc { direction = 270 } }
            else if (angle = 180) { direction = 180 ; with npc { direction = 0 } }
            else if (angle = 270)  { direction = 270 ; with npc { direction = 90 } }
        with npc { alarm[11] = 1 }
        speed = 0
        image_index = 0
        exit
    }
}
 

Nidoking

Member
if instance_place(x,y,parNpc)
You're only allowing interaction if your instance overlaps with the parNpc. From what you've shown so far, it looks like you just want to be facing the parNpc. You should check and see if there's an instance some distance in the direction you're facing.
 
You're only allowing interaction if your instance overlaps with the parNpc. From what you've shown so far, it looks like you just want to be facing the parNpc. You should check and see if there's an instance some distance in the direction you're facing.
And what would be the best way to do this? place_meeting, or something similar for example?
 

Nidoking

Member
instance_place is more typical, since you need that instance ID to make sure you're accessing the right instance. But you have to offset the x and y, or you're only checking the instance's current position for collisions.
 
instance_place is more typical, since you need that instance ID to make sure you're accessing the right instance. But you have to offset the x and y, or you're only checking the instance's current position for collisions.
My next question would be, would having the step code recognize an object id to determine which object it's triggering work? Because what I believe is happening is the code is seeing that there is something using parNpc almost touching another parNpc so it's thinking they're the same object, if that makes sense. And if there would be a way to distinguish the object id from the parent to make this work, how would I go about coding that? I'll admit, this is my first time using parent functions in gamemaker, I'm fine with gml and everything, but parents are throwing me off a little bit as I'm not completely used to them just yet, so any examples or help would be very appreciated.
 

Nidoking

Member
My next question would be, would having the step code recognize an object id to determine which object it's triggering work? Because what I believe is happening is the code is seeing that there is something using parNpc almost touching another parNpc so it's thinking they're the same object, if that makes sense. And if there would be a way to distinguish the object id from the parent to make this work, how would I go about coding that? I'll admit, this is my first time using parent functions in gamemaker, I'm fine with gml and everything, but parents are throwing me off a little bit as I'm not completely used to them just yet, so any examples or help would be very appreciated.
You should set your check so that your collision box is only overlapping one parNpc at a time. Every instance has an object_index variable that tells you what specific object type it is, so you can check collision using a parent object and then get the specific object type from the instance.
 
I'm now encountering:
Unable to find instance for object index -4
at gml_Object_objPlayer_Step_0 (line 107) - npc = instance_nearest(x,y,objNPCExtender).link

I haven't changed much of the code aside from moving the < 2 and < 4 from beside the if distance_to_object(parNpc) {
 

Nidoking

Member
This means that it's not finding an instance of objNPCExtender. Always check to see if the instance is noone before attempting to use it.
 
So, I kind of find it funny. I completely redid the code, and last night it was working! But now, today, even though I have changed absolutely nothing at all, no dialog boxes are popping up XD

GML:
if (canmove
&& keyboard_check_pressed(global.kb_choose)
&& distance_to_object(objNPCExtender)
&& !( instance_exists(obj_inv) && instance_exists(objStorage))) {
    
    var _list = ds_list_create();
    var _hits = instance_place_list(x,y,objNPCExtender, _list, true);
    for (var _i = 0, _npc; _i < _hits; _i++)
    {
        _npc = _list[| _i];
        if !_npc.visible continue;
        
        _npc.alarm[11] = 1;
        direction = point_direction (x, y, _npc.x, _npc.y);
        speed = 0;
        image_index = 0
    }

if distance_to_object(parDoor)
    
    var _list = ds_list_create();
    var _hits = instance_place_list(x,y,parDoor, _list, true);
    for (var _i = 0, _npc; _i < _hits; _i++)
    {
        _npc = _list[| _i];
        if !_npc.visible continue;
        
        _npc.alarm[11] = 1;
        direction = point_direction (x, y, _npc.x, _npc.y);
        speed = 0;
        image_index = 0
    }

if distance_to_object(parNpc)

    var _list = ds_list_create();
    var _hits = instance_place_list(x,y,parNpc, _list, true);
    for (var _i = 0, _npc; _i < _hits; _i++)
    {
        _npc = _list[| _i];
        if !_npc.visible continue;
        
        _npc.alarm[11] = 1;
        direction = point_direction (x, y, _npc.x, _npc.y);
        speed = 0;
        image_index = 0
    }
    ds_list_destroy(_list);
}
 

Nidoking

Member
This is a good time to learn to use the debugger. Trace through where it should be creating the instance and see what it's doing that's different from what you think it should be doing, and why.
 
This is a good time to learn to use the debugger. Trace through where it should be creating the instance and see what it's doing that's different from what you think it should be doing, and why.
I have definitely tried that, I even tried cleaning the whole thing and nothing is really showing up as problematic.
 

Nidoking

Member
nothing is really showing up as problematic.
So the dialog boxes are popping up? Great! You can mark the thread as "SOLVED" so people don't keep trying to help you when you've already solved the problem.

Or did you mean to say that you don't know enough about the debugger to figure out what the problem is, and you need further help with it, but instead of saying that, you just assumed random people looking at parts of your game would somehow find something the debugger isn't equipped to do?
 
So the dialog boxes are popping up? Great! You can mark the thread as "SOLVED" so people don't keep trying to help you when you've already solved the problem.

Or did you mean to say that you don't know enough about the debugger to figure out what the problem is, and you need further help with it, but instead of saying that, you just assumed random people looking at parts of your game would somehow find something the debugger isn't equipped to do?
I had asked for somebody to show me how to fix a problem in my code, and while people have suggested trying this and that, it hasn't worked out for me, which is why I asked for a visual example so I can learn from the example instead of trying over and over on the same thing. I learn better through visuals, it's easier to comprehend when there's a visual for me because sadly, learning disabilities do inhibit things like this. I'm new to using parent/child objects, I tried multiple things to get them to work with no success thusfar, I've been stuck on this particular issue for a couple of weeks after getting everything else coded out flawlessly, but this one error involving parent-child is confusing me. I didn't assume people would find something the debugger couldn't; I asked for a visual example of how to do something like I'm trying to do, so I can learn from it.
 

Nidoking

Member
Well, if you really have to know how basic parenting works...

GML:
var instid = instance_place(somex, somey, parent_object_id);

if (instid != noone)
{
  // instid.object_index is the index of the object that instid is an instance of
}
But you're describing a problem with the functionality of your game that you claim happened due to no change that you made. Click the broom icon, and if that doesn't work, it's something you changed. 99.9999999999% of the problems people here claim are due to Game Maker not working properly are something they did wrong. Using distance_to_object as if it were a boolean function, for example. But you seem to be saying that something should be happening in your game that isn't happening, while you've posted no code that would make the thing that you say should happen happen, and you've listed many things that have nothing to do with the problem and said anything but your code is to blame. It's your code. It's going to continue to be your code unless you can prove it's not. There is precisely one person in this world who can do that, and it's you. If you can't do it, then it's not going to happen. You've got to put debug messages in your code so you can see the statements print or not print, or use breakpoints and step through the code you think should be running, or just divide something by zero and see whether the game crashes if that's the best idea you've got. I literally can't explain in a forum thread how you do that, because I haven't seen the relevant code. And even that would be no more than a step in a direction. There's no picture I can draw you, and if the trillions of videos on Youtube don't explain things well enough for you, my contribution wouldn't change that either.

Oh, and you're missing the curly braces on two of your if statements.
 
Top