#Multiplayer Chatbox Help

1 messages · Page 1 of 1 (latest)

dry bridge
#

So I have a control node called Chat with a chat script
Inside it I have a TextEdit named ChatBox
And I have a LineEdit named ChatInput
And I of course got a Character2dBody as the player with a player script.
Mult Sync is set up to both the TextEdit.text and even tried with the LineEdit.text

I've got it so the person who sends it can see their message..
And even the print shows the other person can supposedly see whats sent.
But the message itself isn't popping up in the other person's actual chatbox.

The Chat Script

extends Control

@onready var chat_box: TextEdit = $ChatBox  #Message
@onready var chat_input: LineEdit = $ChatInput
@onready var but_send: Button = $ButSend
@onready var usrmn = $"../../../../..".name  # Replace with player inputted name
@onready var player = $"../../../../.."

func submit() -> void:
    _on_but_send_pressed()


func _on_but_send_pressed() -> void:
    rpc("msg_rpc", usrmn, chat_input.text)
    chat_input.text = ""


@rpc ("any_peer", "call_local")
@warning_ignore("shadowed_variable")
func msg_rpc(usrmn, text):
    print("Usrmn: ", usrmn, "  Text: ", text)
    chat_box.text += str(usrmn, ": ", text, "\n")
    chat_box.scroll_vertical = chat_box.get_line_count()```
#

The area of the Player script containing the input and onready stuff

@onready var chat_input: LineEdit = $"Sprite2D/Camera2D/Interface/Grid Border/Chat/ChatInput"
@onready var chat: Control = $"Sprite2D/Camera2D/Interface/Grid Border/Chat"

func _physics_process(_delta: float) -> void:
    if !is_multiplayer_authority():
        return
    
    move_speed = 0.5 - (0)
    if movementTween == null or !movementTween.is_running():
        if !acting and !moving and !typing:
            # --- Detect input direction ---
            var dir := Vector2.ZERO
            
            if Input.is_action_pressed("Left"):
                $Sprite2D.frame = 3
                dir.x -= 1
            if Input.is_action_pressed("Right"):
                $Sprite2D.frame = 2
                dir.x += 1
            if Input.is_action_pressed("Up"):
                $Sprite2D.frame = 1
                dir.y -= 1
            if Input.is_action_pressed("Down"):
                $Sprite2D.frame = 0
                dir.y += 1
                
            if dir != Vector2.ZERO:
                _move(dir)
        
        if typing:
            if Input.is_action_just_pressed("Enter"):
                chat.submit()
                typing = false

func _on_chat_input_focus_entered() -> void:
    #print("Entered Typing")
    typing = true

func _on_chat_input_focus_exited() -> void:
    #print("Exited Typing")
    typing = false

func _input(event: InputEvent) -> void:
    if event is InputEventMouseButton and event.pressed:
        if not chat_input.get_global_rect().has_point(event.position):
            chat_input.release_focus()
#

With all that confusion said, if I don't get back to anyone's message right away I apoligize, but I appreciate any insight and will respond if anyone does. Feel free to @ me. But imma go lay down for now.

#

And if ya recogonize what i'm basically porting- Hey, hello fellow 'not cows'.

slender smelt
dry bridge
#

Line 20:Expected opening "(" after function name.
Line 20:Expected parameter name.
Line 20:Expected closing ")" after function parameters.
Line 20:Expected end of statement after bodyless function declaration, found "." instead.
Line 21:Unexpected "Indent" in class body.
Line 22:Unexpected identifier "chat_box" in class body.
Line 23:Unexpected identifier "chat_box" in class body.
Line 23:Expected end of file.

slender smelt
#
func _on_but_send_pressed() -> void:
    msg_rpc.rpc(usrmn, chat_input.text)
    chat_input.text = ""
dry bridge
#

Got it, same issue tho

#

Only popping up on one screen, the person who sent it

#

I gotta head to work, but appreciate the help

dry bridge
#

Still got no idea why it isn't working

dry bridge
#

Boils down to something along the lines of..

#

chat_box.text += str(usrmn, ": ", data, "\n")