Make it easier for new users to format and preview code in their posts

Suggestions to help new users posting.

#1) Use AI to determine if there is more than couple of lines of code in the post and display an embedded message at the top giving how to format code instructions.

#2) Move the Preformatted text icon to be at the front. Rename it to Format Code. Many times it even hides on my tablet to the gear icon.

#3) Your topic similar to… panel on the right is confusing to many new users as they don’t know there is a preview behind it. I would change the esc X button changed to just say Preview Post

8 Likes

All-around excellent suggestions. If you’re looking to help someone with a topic, it’s mildly frustrating to be met with code that isn’t formatted. There have been many times in which I completely skip reading a post simply because of this very issue.

I doubt that you need to use AI to detect code that is in need of formatting. You likely just need a list of keywords (or keyword combinations) that prompt the hint.

4 Likes

I’m just thinking one of the reasons also is that when code is pasted in to the post, why not at least keep the tabs or at least convert them to spaces (maybe 5)?

Example code I just pasted. It looks fine when I paste it. However the tabs are erased which messes it up. At the very least convert them to spaces. May not look color coded, but in most case it is understood.

func press_enter():
var enter_key:=InputEventKey.new()
enter_key.keycode=KEY_ENTER
enter_key.pressed = true
Input.parse_input_event(enter_key)

func _on_gui_input(event):
if event is InputEventKey and event.keycode >= 32 and event.keycode <= 167:# and event.is_pressed():
var caretln=get_caret_line()
if caretln > MAX_LINES:
accept_event()
elif get_line(caretln).length() > MAX_LENGTH:
if get_line_count() < MAX_LINES:
press_enter()
else:
accept_event()

And this is what it looks like formatted without the language tag.

func press_enter():
	var enter_key:=InputEventKey.new()
	enter_key.keycode=KEY_ENTER
	enter_key.pressed = true
	Input.parse_input_event(enter_key)

func _on_gui_input(event):
	if event is InputEventKey and event.keycode >= 32 and event.keycode <= 167:# and event.is_pressed():
		var caretln=get_caret_line()
		if caretln > MAX_LINES:
			accept_event()
		elif get_line(caretln).length() > MAX_LENGTH:
			if get_line_count() < MAX_LINES:
				press_enter()
			else:
				accept_event()
1 Like

Posting here so to be linked for later use instead of re-typing this every time


Make sure you paste scripts instead of screenshots. To properly format pasted code use three ticks ``` at the start and end of your paste like so:

```
# type or paste code here
func _ready() -> void:
    print("My ready function!")
```

Results in:

# type or paste code here
func _ready() -> void:
    print("My ready function!")

Press the </> button or ctrl+e in the forum to create these ticks.

2024-09-02-190029_478x181_scrot

9 Likes

The explanation when creating a new post should include formatting code using ``` or [code] [/code] and mention the code button.
Currently it is pretty vague for people not familiar with these kind of things.

Or maybe rework the code icon to show </code> to make it clearer.

3 Likes

May be AB-testing hiding the button, the ctrl+e shortcut has also been removed for me? Seems like a really bad call. I think it’s AB tests as this change isn’t on chromium.

2024-10-30-145731_547x116_scrot

1 Like

The forum app is Powered by Discourse (note at bottom). I am wondering what control if any does an admin have over customization. Any admins here who could answer that with regards to this topic?

Just putting in my two cents here, they should definitely have formatted code in the new user tutorial. It’s pretty much an essential feature.

Plus, all the other suggestions in this post should absolutely be implemented at some point. Just to smooth out the new user experience. Any bit helps with redundancies.

3 Likes

I would like to add to this conversation.
I just found out (after my formated text showed in grey for some reason and had to google it) that you can manually set the language of the highlight by typing it after the ```

example

```gdscript
#CODE
2 Likes

Ok so going back to my AI thought to detect if there is code in a post and notify user posting to format it using tags.

I asked the following question from gemini.google.com. Not only did gemini understand the code it gave me pretty detailed explanation, although I could tell it to spare me the details.

Please reformat this text below.

I have this code and do not understand it. Please help me all you experts. I am just a beginner!

func press_enter():
var enter_key:=InputEventKey.new()
enter_key.keycode=KEY_ENTER
enter_key.pressed = true
Input.parse_input_event(enter_key)
func _on_gui_input(event):
if event is InputEventKey and event.keycode >= 32 and event.keycode <= 167:# and event.is_pressed():
var caretln=get_caret_line()
if caretln > MAX_LINES:
accept_event()
elif get_line(caretln).length() > MAX_LENGTH:
if get_line_count() < MAX_LINES:
press_enter()
else:
accept_event()

And here is the answer from gemini (ggogle’s AI)