Привет, недавно я загорелся желанием сделать собственный мессенджер, но у меня возникла проблема с нодам. В Ютюбе есть пару файлов об этом, но все равно как то не понятно изложение авторов на ютюбе. Если вы не хотите или не знаете как мне помочь, мы можем обсудить детали либо просто откажитесь от выполнения, обиду держать не буду:3 спасибо!
Hi there!
I have moved your comment into it’s own topic. Also while we don’t forbid using other languages, please keep in mind that the chances of getting help are higher if you use english.
You question so far is very vague, it would be good to add more details what you are trying to do and where you are stuck.
Errors on line 16
extends Control
@onready var chatLog = get_node("VBoxContainer/RichTextLabel")
@onready var inputLabel = get_node("VBoxContainer/HBoxContainer/Label")
@onready var inputField = get_node("VBoxContainer/HBoxContainer/LineEdit")
var groups = [
{'name': 'Team', 'color': '#00abc7'},
{'name': 'Match', 'color': '#ffdd8b'},
{'name': 'Global', 'color': '#ffffff'}
]
var group_index = 0
var user_name = 'Player'
func _ready():
inputField.connect("text_entered", self,'text_entered')
change_group(0)
func _input(event):
if event is InputEventKey:
if event.pressed and event.scancode == KEY_ENTER:
inputField.grab_focus()
if event.pressed and event.scancode == KEY_ESCAPE:
inputField.release_focus()
if event.pressed and event.scancode == KEY_TAB:
change_group(1)
func change_group(value):
group_index += value
if group_index > (groups.size() - 1):
group_index = 0
inputLabel.text = '[' + groups[group_index]['name'] + ']'
inputLabel.set("custom_colors/font_color", Color(groups[group_index]['color']))
func add_message(username, text, group = 0, color = ''):
chatLog.bbcode_text += '\n'
if color == '':
chatLog.bbcode_text += '[color=' + groups[group]['color'] + ']'
else:
chatLog.bbcode_text += '[color=' + color + ']'
if username != '':
chatLog.bbcode_text += '[' + username + ']: '
chatLog.bbcode_text += text
chatLog.bbcode_text += '[/color]'
func text_entered(text):
if text =='/h':
add_message('', 'There is no help message yet!', 0, '#ff5757')
inputField.text = ''
return
if text != '':
add_message(user_name, text, group_index)
print(text)
inputField.text = ''
See: .connect() Object to Callable issues - #2 by njamster You’re trying to use Godot 3 syntax in Godot 4.
I arranged the nods like this Video But when I started writing the code, I discovered that it was written for a year from 3. And I still can’t solve the error in line 16. What can you say about this?
I already linked you a solution (for the exact same issue in another thread):
inputField.connect("text_entered", text_entered)
What you’re using is – as you correctly identified – the syntax used in Godot 3!
Ok!
But unfortunately there was another error unknown to me
Строка 51 (UNREACHABLE_CODE): Unreachable code (statement after return) in function “text_entered()”.
Ps: I already looked at that topic, but I just didn’t understand the solution, sorry for my lack of composure.
This should be a warning, not an error. Important difference, since errors will halt the execution of your game, while warnings won’t (although ignoring them may still result in buggy behavior). This warning in particular tells you that some portion of your code will never be actually executed. Minimal example:
func dummy_function() -> bool:
return true
print("This will never get printed!")
Here, the function will always return before the print
statement, resulting in a warning about unreachable code, that can only be avoided by returning later (after the line containing the print
call).
In the code you shared earlier, this shouldn’t happen, though! So either you changed something that you have yet to share with us, or you messed up the indentation of the return
statement such that it will always return
after the first if
statement – regardless of whether the condition evaluates as true
or false
.
Thanks to everyone who contributed to this topic. This helped solve half the problems, thanks!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.