0 votes

I am trying to set up multiplayer for my game, this of course includes a chatbox. After seeing how a few others have done this, I decided to follow along and use a RichTextLabel. the setup is fairly straight forward:

enter image description here

extends Control

onready var chat_log = $VBoxContainer/RichTextLabel
onready var input_label = $VBoxContainer/HBoxContainer/Label
onready var input_field = $VBoxContainer/HBoxContainer/LineEdit

var groups = [
    {'name':'Global', 'color':'#ffffff'},
    {'name':'System', 'color':'#edbd00'},
    {'name':'Party', 'color':'#30f74f'},
    {'name':'Whisper', 'color':'#00ede8'},
   ]

var group_index = 0
var player_name = 'Test'
var input_focus = false

func _input(event):
    pass
    if event is InputEventKey:
        if event.is_action_released("T") and input_field != get_focus_owner():
            input_field.grab_focus()

func _on_LineEdit_text_entered(new_text):
    var message_info = {
        'message':new_text,
        'color':groups[group_index]['color'],
        'username':Game.player_name,
        'group':groups[group_index]['name']
       }
    rpc("add_message", message_info)
    input_field.text = ''
    input_field.release_focus()

sync func add_message(message_info):
    chat_log.text += '\n'
    chat_log.text += message_info['group'] + '/' + message_info['username'] + ': '
    chat_log.text += message_info['message']

func _on_OptionButton_item_selected(id):
    group_index = id

I would expect the rich text label to properly manage the linecount but for some reason it is stacking different players text on top of one another:
enter image description here
If anyone knows anything about this or what I'm doing wrong, I'd really appreciate the help.

in Engine by (12 points)

Your code looks fine. Have you made sure that there really is only one RichTextLabel? You can pause the game by pressing F7 and take a look at the remote scene tree.

enter image description here

This is a snap of the Remote scene tree. I believe there's only one :S

Mhm, looks fine as well. Can you upload an example project? I cannot reproduce your issue.

GitHub

I am currently working off of the branch 'Experimental'

ChatBox is found under res://Player/PlayerGUI/ChatBox

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.