Skip to content

Calling an object created mid-cutscene

I'm working on a complex cutscene which involves a character appearing and disappearing (and doing other actions in-between). For that, I'm using GestaltCreate and then DestroyObject.

The thing is, after I create the creature, I can't refer to it with GetObjectByTag, but that works inside the function. Here's what I mean:
        WORKS:

        GestaltCreate(17.0, wHayford, OBJECT_TYPE_CREATURE, "hayford");

        DelayCommand(22.0, AssignCommand(GetObjectByTag("Hayford"), SpeakString(HAYFORD_THREAT_1, TALKVOLUME_SHOUT)));
        DelayCommand(26.0, AssignCommand(GetObjectByTag("Hayford"), SpeakString(HAYFORD_THREAT_2, TALKVOLUME_SHOUT)));
        DelayCommand(30.0, AssignCommand(GetObjectByTag("Hayford"), SpeakString(HAYFORD_THREAT_3, TALKVOLUME_SHOUT)));


        DOES NOT WORK:

        GestaltCreate(17.0, wHayford, OBJECT_TYPE_CREATURE, "hayford");

        oHayford = GetObjectByTag("Hayford");

        DelayCommand(22.0, AssignCommand(oHayford, SpeakString(HAYFORD_THREAT_1, TALKVOLUME_SHOUT)));
        DelayCommand(26.0, AssignCommand(oHayford, SpeakString(HAYFORD_THREAT_2, TALKVOLUME_SHOUT)));
        DelayCommand(30.0, AssignCommand(oHayford, SpeakString(HAYFORD_THREAT_3, TALKVOLUME_SHOUT)));

From my understanding, the problem is the DelayCommand, which makes GetObjectByTag try to refer to an object that doesn't exist yet.

Is there any workaround for this? Like, is there any way of calling an object with a delayed response?

Comments

  • KamirynKamiryn Member Posts: 74
    The problem is that the creation of hayford is delayed within GestaltCreature(). That's the reason why GetObjectByTag can't return hayford - he doesn't exist yet.
  • AncarionAncarion Member Posts: 155
    It would be easiest to keep the version you have listed first. It really won't cause too many issues to call GetObject() a few times in a cutscene. If there's some reason you want to avoid that, then the first thing that comes to mind is making a new private function to handle the second part of your code, including the needed delay to GetObjectByTag(). For example, put this function before the void main() in your script:

    void hayfordSpeak(object oHayford=OBJECT_INVALID)
    {
    oHayford=GetObjectByTag("Hayford");
    AssignCommand(oHayford,SpeakString(etc...));
    DelayCommand(4.0,AssignCommand(oHayford,etc...);
    DelayCommand(8.0,AssignCommand(oHayford,etc...);
    }

    And then add that after the gestalt command, like:

    GestaltCreate(etc...);
    DelayCommand(22.0,hayfordSpeak());
  • gpeddinogpeddino Member Posts: 50
    Thank you both for the answers.

    I decided to stick to the GetObjectByTag for now. The script I'm working on already has several different functions and adding more would make things a bit too cluttered. I just wanted to find out if there was a workaround I wasn't aware of.
Sign In or Register to comment.