Forum Discussion

PurriCatStudio's avatar
13 days 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 player or save the chat history so that it can later be added to the context when the player returns.

It would also let me parse for keywords and maybe have NPCs attitudes to players change depending on what was said.

I could also use the responses to start quests, unlock doors, or give rewards.

I'm not sure why NPCs text response isn't given to us but please do so or let me know how because I can't figure it out.

  • 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

     

1 Reply

  • 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