Narrative Design Tutorial(s) for PlayCanvas

Hi Convai-Community !!

I’m building a proof of concept that implements Convai in PlayCanvas.
I need some control on the Narrative Design but have become stuck.
Are there any tips or tutorials for working with the Narrative Design in PlayCanvas?

Thanks,

To be more specific I’d like to receive and dispatch narrative events within a PlayCanvas application. - Any clues

Hey Nick,

convaiClient.setResponseCallback(function(response) {
        
        if(response.hasBtResponse()){
            var btResponse = response.getBtResponse();
            conversationActive = true;
            if(btResponse.array[2] === 'fc6eff80-4d21-11ef-85d1-42010a7be011'){
                followMeCalled = true;
            }
        }
}

You will recieve bt response in response callback with an id. You can match that to invoke an animation/action etc.

You can add triggers and sections from playground. After setting up these you just need to manage animations based on bt response. The narrative will be taken care of from the backend.

You can use narrative template keys for subsituting or adding values like current time etc:

const client = new convaiClient({
  apiKey: 'your-api-key',
  characterId: 'your-character-id',
  narrativeTemplateKeysMap: getNarrativeTemplateKeys()
});

convaiClient.invokeTrigger("triggerName", "message");

Incase you want to call a trigger directly.

1 Like

@Saurav Thanks so much for the reply.

convaiClient.setResponseCallback(function(response) {
        
        if(response.hasBtResponse()){
            var btResponse = response.getBtResponse();
            conversationActive = true;
            if(btResponse.array[2] === 'fc6eff80-4d21-11ef-85d1-42010a7be011'){
                followMeCalled = true;
            }
        }
}

I’m assuming this is code is listening for the specific trigger that’s fired, is that correct?

Also, for example, with the Unity plugin I’m able to use the OnSectionStart() and OnSectionEnd() to invoke functions. Is there something similar in PlayCanvas?

Thanks again,

Nick

These are Unity Events in the Unity Plugin. You can also do the same thing manually. When you change section, you can call the OnSectionEnd event for the current Section, then call the OnSectionStart event for the new section.

@K3 and @Saurav, Thanks so much guys.

What is the syntax for OnSectionStart / OnSectionEnd for PlayCanvas?
Can you provide a code snippet?

And on my other question, does the snippet provided by @Saurav listen for the specific trigger that’s fired.

Sorry if this is obvious but it would be helpful to know.

Thanks,

What is the syntax for OnSectionStart / OnSectionEnd for PlayCanvas?
Can you provide a code snippet?

This is an extra customization. It is entirely up to you to develop it.