Impossible bug? Does anyone have explanation for this?

I found a warning in log. Looked into a script where is a sanity check, but how the hell can this happen?

        object oPCCopy = GetLocalObject(oPC,"PC_COPY");
        if(GetIsObjectValid(oPCCopy))
        {
            DestroyObject(oPCCopy);
        }
        oPCCopy = CopyObject(oPC,GetLocation(GetObjectByTag("WP_COPYPLAYER")),OBJECT_INVALID,"pccopy");
        if(!GetIsObjectValid(oPCCopy))
        {
            WriteTimestampedLogEntry("WARNING! oPCCopy not valid in sh_volnasek72!!!");
            return;
        }
        SetLocalObject(oPC,"PC_COPY",oPCCopy);

Yes, waypoint WP_COPYPLAYER does exists. This code is being executed relatively often and is executed from Activate Item module event ( object oPC = GetItemActivator(); ) , I haven’t heard from players that it wasn’t working and I tested it myself - never had an issue (probably the player who triggered this sanity check just used it again and then it worked so he didn’t report).

I am using NWN-EE build 36-12.

EDIT: I am not using tag-based scripting, just a simple ExecuteScript(GetTag(oItem)) in activate item event. No such script in acquire/unacquire/equip/unequip exists.

Just verified my own code. All I can say is that oCopy = CopyObject(oPC, …) works in 36-12 and that for the returned object GetIsObjectValid(oCopy) returns TRUE.

Add some more debug messages to your code, check oPC, check the waypoint, …

Yeah, when I took the time to write this all down I realized that the most likely culprit is that the script must be firing from somewhere else than Activated. So I added more warnings in case it ever happens again.

CopyObject definitely works, I just thought that maybe it can fail under some circumstances. But as you say, it is much more likely that the oPC was invalid to begin with. Will see when it happens again…

consider this solved

You can use GetScriptName() and GetScriptRecursionLevel() to get the name of the calling script (just in case you don’t know yet about these two newer scripting commands).

1 Like