So, you are about to make a chat without knowing basic things…
(Haven’t you been sent to Your first 2D game from the official documentation yet?)))
It will be about @onready and everything else.
You have to understand that when you make a video that was recorded when Godot 4 didn’t even exist yet, there will be some differences… but I made a code from it: everything works if you dig around and think about where the necessary commands went…
I provide the code below, with some comments.
extends Control
@onready var chatLog = $VBoxContainer/RichTextLabel
@onready var inputLabel = $VBoxContainer/HBoxContainer/Label
@onready var inputField = $VBoxContainer/HBoxContainer/LineEdit
# onready -> @onready, also, export -> @export
var groups = [
{'name': 'Team', 'color': '#34c5f1'},
{'name': 'Match', 'color': '#f1c234'},
{'name': 'Global', 'color': '#ffffff'},
]
var group_index = 0
var user_name = "Emilio"
func _ready():
# inputField.connect("text_changed", self, "text_changed")
inputField.connect("text_submitted", text_submitted)
add_message('Godot', "The engine: ")
change_group(0)
# text_entered, -> text_submitted
func _input(event):
if event is InputEventKey:
if event.pressed and event.keycode == KEY_ENTER:
inputField.grab_focus()
if event.pressed and event.keycode == KEY_ESCAPE:
inputField.release_focus()
if event.pressed and event.keycode == KEY_TAB:
change_group(1)
# scancode -> keycode
func change_group(value):
group_index += value
if group_index > (groups.size() - 1):
group_index = 0
inputLabel.text = '[' + groups[group_index]['name'] + ']'
inputLabel.set('theme_override_colors/font_color', Color(groups[group_index]['color']))
func add_message(username, text, group = 0):
chatLog.append_text('\n')
chatLog.append_text('[color=' + groups[group]['color'] + ']')
chatLog.append_text('[' + username + ']: ')
chatLog.append_text(text)
#chatLog.append_text('[/color]')
# bbcode_text -> append_text()
func text_submitted(text):
if text == '/h':
add_message('help', "There is no help written yet.", 2)
inputField.text = ''
return
if text != '':
print(text)
add_message(user_name, text, group_index)
inputField.text = ''
True, after doing this, I found out that there is no internetwork here)))
But it is in other search results.