• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

SOLVED Key Logic for NPC interaction just crashes the game, don't know how to fix it.

D

DevilKap

Guest
The program for the "Key Logic" related to NPC interaction is in my PlayerStateFree right now, whenever I actually "use" it, the game crashes.
Program below:
Code:
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
function PlayerStateFree(){
   
//Image Speed
image_speed = 0.5

//Movement
hSpeed = keyRight - keyLeft;
vSpeed = keyDown - keyUp;

if(hSpeed != 0 or vSpeed != 0){
dir = point_direction(0,0,hSpeed,vSpeed);
moveX = lengthdir_x(speedWalk, dir);
moveY = lengthdir_y(speedWalk, dir);

//Collision Function
PlayerCollision();

//Set Sprite
switch(dir){
    case 0: sprite_index = walkRight; break;
    case 45: sprite_index = walkUpRight; break;
    case 90: sprite_index = walkUp; break;
    case 135: sprite_index = walkUpLeft; break;
    case 180: sprite_index = walkLeft; break;
    case 225: sprite_index = walkDownLeft; break;
    case 270: sprite_index = walkDown; break;
    case 315: sprite_index = walkDownRight; break;
    }
} else {
    image_index = 0
}

//Change State


if(keyRun)
{
    state = PlayerStateRun;
}


//Activate key logic
if(keyActivate)
{
    //1. Check for an entity to activate
    //2. If there's nothing, or something without a script, do nothing
    //3. Otherwise, activate diologue
    //4. If the entity is an NPC, make it face towards the player
   
    var _activateX = lengthdir_x(10, direction);
    var _activateY = lengthdir_y(10, direction);

    activate = instance_position(x+_activateX, y+_activateY, pEntity);

    if (activate == noone || activate.entityActivateScript == -1)
    {
        state = PlayerStateFree;
    }
    else
    {
         ScriptExecuteArray(activate.entityActivateScript, activate.entityActivateArgs);
    }
   
    //NPC dir
    if (activate.entityNPC)
    {
        with (activate)
        {
            direction =point_direction(x,y,other.x,other.y);
        }
    }
}  
}
Highlight:
Code:
//Activate key logic
if(keyActivate)
{
    //1. Check for an entity to activate
    //2. If there's nothing, or something without a script, do nothing
    //3. Otherwise, activate diologue
    //4. If the entity is an NPC, make it face towards the player
   
    var _activateX = lengthdir_x(10, direction);
    var _activateY = lengthdir_y(10, direction);

    activate = instance_position(x+_activateX, y+_activateY, pEntity);

    if (activate == noone || activate.entityActivateScript == -1)
    {
        state = PlayerStateFree;
    }
    else
    {
         ScriptExecuteArray(activate.entityActivateScript, activate.entityActivateArgs);
    }
   
    //NPC dir
    if (activate.entityNPC)
    {
        with (activate)
        {
            direction =point_direction(x,y,other.x,other.y);
        }
    }
}
I'm wondering if I should just make this a function and then associate it with keyActivate?

edit: the crash log shows as follows-
___________________________________________
############################################################################################
ERROR in
action number 1
of Step Event0
for object oPurplon:

Unable to find instance for object index -4
at gml_Script_PlayerStateFree (line 67) - if (activate.entityNPC)
############################################################################################
gml_Script_PlayerStateFree (line 67)
gml_Object_oPurplon_Step_0 (line 19)
 
Last edited by a moderator:
D

DevilKap

Guest
Fixed- apparently it's because with the
GML:
if (activate.entityNPC)

    {

        with (activate)

        {

            direction =point_direction(x,y,other.x,other.y);
it should be
GML:
if (activate == noone || activate.entityNPC)

    {

        with (activate)

        {

            direction =point_direction(x,y,other.x,other.y);
 
Last edited by a moderator:
Top