Forum Discussion

PurriCatStudio's avatar
2 months ago
Solved

Request: Get AI Responses as text

AI already responds with text that gets put into the speech bubble but devs do not have a way to access this text. I would love to be able to do so. It would let me persist NPCs responses to a pl...
  • jimrif's avatar
    2 months ago

    The NPC text response is available via events.  You can get the full response or the information broken down by sentences.  Here is an example part of the script:

    override preStart() {
        this.npc = this.entity.as(Npc);
        this.connectNetworkEvent(this.npc, NpcEvents.OnNpcPartialResponse, (data: { text: string }) => {
          this.handleOnNpcPartialResponse(data.text);
        });
        this.connectNetworkEvent(this.npc, NpcEvents.OnNpcFullResponse, (data: { text: string }) => {
          this.handleOnNpcFullResponse(data.text);
        });
      }
    
      private handleOnNpcPartialResponse(text: string) {
        console.log("Received Sentence: " + text);    
      }
    
      private handleOnNpcFullResponse(text: string) {
        console.log("Received Full Response: " + text);    
      }

    There are also other useful events in NpcEvents.

    Also, this video is really great for NPC information.  Check it out if you haven't already:

    https://www.youtube.com/watch?v=p-haUOGdgpI