Hi all,

Beginner at Godot here, I am sure you will notice. Really loving this engine so far!

Quick question, I am working on a console for my game, which I implemented as a TextEdit. What I want is:

To show the console as soon as the player starts typing (works) To show a prompt (>) on the first line when the player opens the console (works) To show a prompt (>) once the player presses enter after a command, on the new line (does not work)

This was my initial code, which sets the cursor before the prompt:

func _input(event): if Input.is_key_pressed(KEY_ENTER): insert_text_at_cursor(">")

And this is how I tried to fix it, which seems to just make a mess of things:

func _input(event): if Input.is_key_pressed(KEY_ENTER): insert_text_at_cursor("\n") current_line += 1 cursor_set_line(current_line) insert_text_at_cursor(">") cursor_set_column(2)

Any thoughts?

The console is going to be a very important part of this game, so I am really focussing on getting this TextEdit thing figured out more.

Thanks!

The engine needs to finish the first loop and then will do the rest (like setting the new prompt) in another loop. You could for example work with _process():

Maybe there is a cleaner way (e.g. in an individual function). If you need _process() for some other work you could also use booleans:

I hope that this will help you.

For reference sake, on Reddit I have been proposed another solution, which I will leave here if anybody ever finds this, looking for a solution. I couldn't tell you anything about the effectiveness of one over the other:

func _input(event): if Input.is_key_pressed(KEY_ENTER): get_tree().set_input_as_handled() insert_text_at_cursor("\n>")

Here is a link to the thread: https://reddit.com/r/godot/comments/7xycun/prevent_newline_in_textedit_or_add_prompt_before/

@theapemachine said: For reference sake, on Reddit I have been proposed another solution, which I will leave here if anybody ever finds this, looking for a solution. I couldn't tell you anything about the effectiveness of one over the other:

func _input(event): if Input.is_key_pressed(KEY_ENTER): get_tree().set_input_as_handled() insert_text_at_cursor("\n>")

Here is a link to the thread: https://reddit.com/r/godot/comments/7xycun/prevent_newline_in_textedit_or_add_prompt_before/

Yep, this one seems more efficient as my suggestion. I would prefer your's. ;-)

5 years later