Hello,

I have a very small basic battleground with 1 unit on left, 1 unit on right, and two buttons Attack and Rest for each.

Under this i have a Patch9Frame with a RichTextLabel

When i Attack i print a text "You hit for 4 points" for example in this frame. When i rest, text is something like "You rest and regain 2 points".

It's "fine"... but the previous text disappear each time i click a button.

get_node("CombatText").set_text("You hit for "+str(_Power)+" points")

How can i do something like mostly all roguelike games or MMORPG, a kind of chat/log windows that can keep track of events, line by line ?

Assuming that you are using the RichTextLabel, then you want to call add_text(). example: get_node("CombatText").add_text("You hit for "+str(_Power)+" points\n") remember to add the '\n' at the end so that it creates a new line. Also, if you want to be able to scroll up and down to view the whole history, then make RichTextLabel a child of ScrollContainer and make sure that you set a minimum size for RichTextLabel or else you may not be able to see it.

Great, thanks !

More questions related to this :

  • i have a scrollbar without using ScrollContainer, is that "normal" ? Why hould i use ScrollContainer then ?
  • With or without ScrollContainer, i didn't find how to move the scroll the the left side instead of the default right. Can i ?
  • i've found this to do exactly what i want : autoscroll when more text is coming. Is this a good way ?

get_node("EventLog").set_scroll_follow(true)

  • I want the new line to come on top not at bottom. How can i invert the text's flow ?

Ok so after looking into your question, I realized that RichTextLabel does already have a built in vscrollbar child, so it is not necessary to make it a child of ScrollContainer. I looked into trying to put the bar on the left and could not get it to work from GDscript, so I snooped around the source code and found where it seems to be hard coded in that the scroll bar will always be on the right. Should be easy enough to change in cpp but that would require building a custom engine. I have actually run into this problem before, not being able to move the scroll bar with GDScript, but never really tried to figure it out till now. If I ever do get around to adding this functionality, I might make a pull request for it to be merged into the project.

set_scroll_follow(true) looks like it works pretty well, but I am not sure how to invert the text though.

Thanks again,

Maybe in next update they will change it. I will keep it that way for now. I have so much more to do and learn.

Hello, not sure if i should open a new topic or not...

var textEvent1 = get_node("/root/Univers/GUI/TextBox/EventLog")
var textEvent2 = get_node("/root/Univers/GUI/TextBox/EventLog").set_scroll_follow(true)

This is the model, and it works when the RichTextLabel is in the same scene : get_node("RichTextLabel").set_scroll_follow(true)

However,

textEvent1.add_text("Text One\n") # No problem, beside no scrolling
textEvent2.add_text("Text Two\n") # Game crash "Invalid call. Nonexistent function 'add_text' in base 'Nil'."

Any idea what i'm doing wrong ?

var textEvent2 = get_node("/root/Univers/GUI/TextBox/EventLog") textEvent2.set_scroll_follow(true)

Thanks,

var textEvent2 = get_node("/root/Univers/GUI/BoxEvent/EventLog")
textEvent2.set_scroll_follow(true).add_text("Scroll ?\n")

Invalid call. Nonexistent function 'add_text' in base 'Nil'.

While that second one is working :

var textEvent = get_node("/root/Univers/GUI/BoxEvent/EventLog")
textEvent.add_text("hmmm")

The method set_scroll_follow() returns void. You'll have to call add_text() on the textEvent variable, like:

var textEvent = get_node("/root/Univers/GUI/BoxEvent/EventLog")
textEvent.set_scroll_follow(true)
textEvent.add_text("new event\n")

Ah now it works, thanks ! It makes sense, but the previous non-working way too...

6 years later