Script action overflow problem

I’m getting tons of action overflows due to a follow script that executes in onHeartbeat. How do i check if the creature is following someone and if NOT execute the script?

Post your script so we can see it. It’s hard to do theoretical debugging.

Basic “follow master” OnHeartbeat with spoken notifications:

void main()
{
    object oMaster = GetMaster();

    // GetCurrentAction tells us what a creature is doing
    // (PC moving with WASD will return ACTION_INVALID)
    switch(GetCurrentAction())
    {
        case ACTION_FOLLOW:
        {
            SpeakString("Already following my master");
            break;
        }
        case ACTION_INVALID:
        {
            if(GetIsObjectValid(oMaster))
            {
                SpeakString("Following master " + GetName(oMaster));
                ActionForceFollowObject(oMaster, 3.0);
            }
            else
            {
                SpeakString("I have no master to follow");
            }
            break;
        }
        default:
        {
            SpeakString("I'm busy with something");
        }
    }
}
1 Like

Thank you! That was exactly what i was looking for. The original script was very simple btw:

Blockquote
void main()
{
if (GetIsInCombat() == TRUE || IsInConversation(OBJECT_SELF) == TRUE)
return;
if (GetIsInCombat() == FALSE || IsInConversation(OBJECT_SELF) == FALSE)
{
object oPC = GetFirstPC();
ActionForceFollowObject(oPC, 2.0);
}
}

It checked to see if the creature was not in combat and in conversation. If yes, it followed the player. But there was no check to see if it was already following thus overtime the overflow occurred.

You can put code between [code][/code] tags for easy formatting and highlighting.

Yes, the idea is that you follow only if the caller is idle (ACTION_INVALID), which takes care of conbat, convo, etc. And it will follow continuously until ClearAllActions is issued, usually automatically by some other event. It should also be the very last part of OnHeartbeat, before attacking, healing, and so on.

EDIT: I added missing else in that script :eyes:.

Probably “… after attacking, healing …” :slight_smile: