ChatComponent

The component supports the chat function for players to communicate with each other.

# Properties

[{"index":"float ChatEmotionDuration","0":"Sets the avatar emote duration."}]

[{"index":"boolean EnableVoiceChat (MakerOnly)","0":"Sets whether to show and use the voice chat button."}]

[{"index":"boolean Expand","0":"The function expands the chat window."}]

[{"index":"boolean HideWorldChatButton (MakerOnly)","0":"This feature allows you to hide the World chat button."}]

[{"index":"boolean MessageAlignBottom (MakerOnly)","0":"This feature allows you to arrange the World chat message to the bottom."}]

[{"index":"boolean UseChatBalloon","0":"The function for players to express a chat message as a chat balloon."}]

[{"index":"boolean UseChatEmotion","0":"The function to use avatar emotes in chat."}]

##### inherited from Component:

[{"index":"boolean Enable (Sync)","0":"Checks whether Component is activated or not."}]

[{"index":"boolean EnableInHierarchy (ReadOnly) (HideFromInspector)","0":"Displays whether this Component is Enable in the hierarchy. If Entity Enable is false regardless of Component Enable, returns false."}]

[{"index":"Entity Entity (ReadOnly)","0":"The Entity that owns this component."}]

# Methods

##### inherited from Component:

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

# Events

[{"index":"ChatEvent","0":"The event occurs when entering a dialog."}]

# Examples

This example adjusts ShowDuration for ChatEmotionDuration and ChatBalloonComponent based on EmotionalType length, and verifies EmotionalType presence in the message via ChatEvent.
    
    
    @Component
    script ChatEmotionActivator extends Component
        @EventSender("Self")
        handler HandleChatEvent(ChatEvent event)
        --------------- Native Event Sender Info ----------------
        -- Sender: ChatComponent
        -- Space: Client
        ---------------------------------------------------------
    
        -- Parameters
        local Message = event.Message
        local SenderName = event.SenderName
        local UserId = event.UserId
        ---------------------------------------------------------
    
        local localId = _UserService.LocalPlayer.OwnerId
        if string.compare(localId, UserId) == false then
        	return
        end
    
        local lowerMessage = string.lower(Message)
    
        local findEmotion = EmotionalType.Invalid
        local len = 23
        for i = 1, len do
        	local key = string.lower(tostring(EmotionalType.CastFrom(i)))
    
        	if lowerMessage:find(key, 1, true ) then
        		log("onChat Find : ", key)
        		findEmotion = EmotionalType.CastFrom(i)
        	end
        end
    
        if findEmotion == EmotionalType.Invalid then
        	return
        end
    
        local chatComponent = self.Entity.ChatComponent
        local duration = #tostring(findEmotion)
        if chatComponent then
        	chatComponent.UseChatEmotion = true
        	chatComponent.ChatEmotionDuration = duration
        end
    
        local balloonComponent = _UserService.LocalPlayer.ChatBalloonComponent
        if balloonComponent then
        	balloonComponent.ShowDuration = duration
        end
    
        log("OnChatEvent ", Message, " duration :", duration)
        end
    end
    

# SeeAlso

  * ChatBalloonComponent
  * EmotionalType
  * ChatEvent
  * UserService