A Little Oddity

Currently I have been helping someone by play-testing their (in development) module. Recently they had been having problems with a cut-scene that had all kinds of weirdness going on. Long story short, I decided to check that it wasn’t a bug in EE by creating a simple module to test it. That is where I came across an oddity.

The module consists of a single 3x3 area. In this area I placed a pedestal, a waypoint and an NPC. I also wrote a small, simple script.

void main()
{
    object oPC = GetClickingObject();
    object oTestSubject = GetObjectByTag("VanHalenJumper");
    object oTarget = GetWaypointByTag("WP_JumpDestination");

    if(GetIsPC(oPC))
        AssignCommand(oTestSubject, JumpToObject(oTarget, FALSE));
}

What is supposed to happen is that when the pdestal is clicked on, the NPC is made to jump to the waypoint. Upon testing, the NPC promptly attacked the PC. Ooops. Adjusted the NPC’s faction to non-hostile. Tried again. This time, while the NPC didn’t attack (yay), nothing happened. So I started adding test code. It wasn’t until I got to this -

void main()
{
    object oPC = GetClickingObject();
    object oTestSubject = GetObjectByTag("VanHalenJumper");
    object oTarget = GetWaypointByTag("WP_JumpDestination");

    if(oTestSubject == OBJECT_INVALID)
        SendMessageToPC(GetFirstPC(), "oTestSubject Invalid");
    else if(oTarget == OBJECT_INVALID)
        SendMessageToPC(GetFirstPC(), "oTarget Invalid");
    else if(oPC == OBJECT_INVALID)
        SendMessageToPC(GetFirstPC(), "oPC Invalid");
    else if(GetIsPC(oPC))
        AssignCommand(oTestSubject, JumpToObject(oTarget, FALSE));
}

that I found the culprit - GetClickingObject(). The problem seems to arise from the fact (according to the Lexicon) that GetClickingObject() uses the same code as GetEnteringObject(). Whatever the reason, GetClickingObject() was returning an INVALID_OBJECT. The solution was to either not test for a PC using GetIsPC() or to use a different event. I chose to use the OnUsed event and and the function GetLastUsedBy(). At this point everything seemed to work. Modified script (with all the test code still in) -

void main()
{
    object oPC = GetLastUsedBy();
    object oTestSubject = GetObjectByTag("VanHalenJumper");
    object oTarget = GetWaypointByTag("WP_JumpDestination");

    if(oTestSubject == OBJECT_INVALID)
        SendMessageToPC(GetFirstPC(), "oTestSubject Invalid");
    else if(oTarget == OBJECT_INVALID)
        SendMessageToPC(GetFirstPC(), "oTarget Invalid");
    else if(oPC == OBJECT_INVALID)
        SendMessageToPC(GetFirstPC(), "oPC Invalid");
    else if(GetIsPC(oPC))
        AssignCommand(oTestSubject, JumpToObject(oTarget, FALSE));
}

So this brings up the obvious question - “What is the point of having the OnClick event with placeables if GetClickingObject() doesn’t appear to work?”. Well given that the player (and hence the PC) is (if we exclude DMs) the only thing that can click on a placeable, you can probably not bother checking that it was the PC that actually performed the clicking. Further if you absolutely must know the PC in your script you can always try the GetNearestPC() function instead. So the OnClick event can be used but be aware of the problem with trying to use GetClickingObject().

Oh and I proved to my satisfaction that the weirdness in the module I was testing didn’t appear to be down to a bug in EE.

Hope you found this useful.

TR

2 Likes

Try GetPlaceableLastClickedBy() when working with placeables.

NWN lexicon says GetClickingObject() is to be used with triggers only.

4 Likes

Didn’t even know about that one. Doesn’t seem particularly logical when they could have made a wrapper function like they did with GetNearestPC() (wrapper for GetNearestCreature()).

It might be a good idea to add the following to the Remarks section of the Lexicon page for GetClickingObject() -

“Do not use with placeables. Use GetPlaceableLastClickedBy() instead.”

TR

2 Likes