Basic Layouts
-
Do you mean the words come from the right and move to the left?
I found a simple way to do it:-
Use a "Label" node, and write the text in it
-
In the inspector (far right), turn on "Clip Text." This is to make the box cut off.
-
Also in the inspector you should see "Displayed Text." Inside it there's a slider called "Visible Ratio." Notice how moving it will change the amount of letters.
-
Set the Horizontal Alignment to Right. Now when you move the Visible Ratio, the text comes in scrolling.
-
You can still see the end of the text, so just add spaces at the end.
-
The last part is the script to change Visible Ratio automatically. Thankfully you just put simple code like this, in the process function:
visible_ratio += delta * 0.1 if visible_ratio == 1: visible_ratio = 0
-
-
I mean if you have a huge amount of text that is too big for the box. Can you get it to scroll down to the bottom of the text and then repeat by going back to the first word ?.
I want to include some history information in some boxes and welcome messages but they will be too long to display in the box.
I want it to start at the top and work its way down to the bottom of the box.
-
Oops, I misunderstood! But I was able to figure it out again
To make it scroll from top to bottom, is pretty similar as my message above but with a RichTextLabel:-
Use the RichTextLabel node, and write the text in it.
-
In the inspector (far right), turn off Scroll Active, and turn on Scroll Following. Basically, scroll following automatically scrolls down to the bottom.
-
Now just add a script. The code is actually the exact same as the one from before!
Remember that this method is easy but there are some shortcomings. One is that the text comes in letter-by-letter, so it might be a little awkward to read. Also, you will need to add a few spaces at the end so that people have enough time to read it all.
Anyway, I hope this helps!
-
-
I have made the adjustments, but where do you enter the script ?
-
The whole script is attached to the RichTextLabel, and the code that I sent should go inside the process function.
-
Hi, do you mean the process section in the "Node" tab ?.
-
I meant you need to make a script for RichTextLabel and then you should see a _process function inside it. I will attach a image.
(This is me in the future. I couldn't upload the image so here is a link to it)
https://imgur.com/a/kyVtk57 -
That is absolutely fantastic, it is weird how sometimes you copy and paste and the code does not work out right. You type it in and there is no issue.
Can I ask how I can get make different sections of script appear one after the other. For example, our club historian has a piece, then the chairman thanking people. Then statistics about both clubs etc. I want to type them both into the one RichTextLabel box but have them appearing one after the other.
If I do it now, write one piece and then the other one below it. It just keeps scrolling down at the bottom of the box and you cannot see it. I want it to be one piece of text at a time.
Example of text I require:
[color=yellow] [font_size=30][b][i] Welcome to our club from Charlie the club historian [/i][/b]
[color=pink] [font_size=20] Welcome to our club that was formed in 2024 and has a long successful career in the league. Many greats have passed through these doors.
[color=yellow] [font_size=30][b][i] Welcome to our club from our Chairman Andy [/i][/b]
[color=blue] font_size=20] Welcome to all our sponsors for todays game and we are thrilled to have you joining us.
These are two separate people with their sections we want to display one by one. We want to do this with many additional data and information.
-
I think I'm finally beginning to understand your entire project... it seems like you are trying to make something similar to a "slideshow" that allows you to go to the next section when you press a button.
Since you are using text, I recommend an array to hold each section, and use Input to switch to the next element. If you don't know what an array is, it is basically a list that lets you store several variables (strings/text in this case), then access each one whenever you want. Each variable that is stored in an array is called an element.
This way, you can keep the text scrolling down. But, it will only show the sections that you want. I will be attaching the code and images in case you need help.
extends RichTextLabel @export var texts: PackedStringArray #holds all the sections of text. @export lets you edit it in the inspector. var current = 0 #a number variable to keep track of which section you are on. func _ready(): visible_ratio = 1 current = 0 func _process(delta): visible_ratio += delta * 0.07 #scrolling text = texts[current] #set the text to the correct section, depending on the variable "current" if visible_ratio == 1: #resetting scrolling after it reaches the bottom visible_ratio = 0 if Input.is_action_just_pressed("ui_right"): #when the right arrow is pressed: current += 1 #go to the next section visible_ratio=0 #reset the scrolling if current >= texts.size(): #OPTIONAL CODE: checking if it already went to the last section current =0
I added some comments so you can understand what everything means. It's still the same script as before, but with some more added.
Now, the code is not enough. You need to add the text into the array. Just add a new element for each section, and copy/paste the text in there.
https://imgur.com/a/41NRROh -
Morning
That is absolutely fantastic.
After a bit of playing about I figured it out and got the array etc working. The only issue is that I want it to be automatic. So it jumps from one text to the next after a period of time.
I have a new found respect for what people put into programming when I am doing this. It must also be quite incredible to quickly create something cool like a game once you are really up to speed on all this.
Thanks for the help so far. It is hugely appreciated
-
I'm glad to have been helpful to you!
As for the automatic switching should be relatively simple. You'll need to make a "timer" variable to track how long it has been. Then you check to see if the timer reached a certain number:var timer = 0 #This creates the timer variable. Put it at the very top func _process(delta): timer += delta #delta is how many seconds elapsed since the last time the code was run. It might be a bit confusing at first but this code is just to make the timer actually count like a timer. if timer >= 10: #when the timer reaches 10 seconds, reset the timer to 0, and go to the next section. timer = 0 current += 1 #same code as before visible_ratio = 0
Hope this helps! Read the comments to better understand it
-
Morning, this seems to clash with the next part of script for the text appearing.
extends RichTextLabel
@export var texts: PackedStringArray #holds all the sections of text. @export lets you edit it in the inspector.
var current = 0 #a number variable to keep track of which section you are on.func _ready():
visible_ratio = 1
current = 0func _process(delta):
timer += delta #delta is how many seconds elapsed since the last time the code was run. It might be a bit confusing at first but this code is just to make the timer actually count like a timer.if timer >= 10: #when the timer reaches 10 seconds, reset the timer to 0, and go to the next section. timer = 0 current += 1 #same code as before visible_ratio = 0 visible_ratio += delta * 0 #scrolling text = texts[current] #set the text to the correct section, depending on the variable "current" if visible_ratio == 1: #resetting scrolling after it reaches the bottom visible_ratio = 0 if Input.is_action_just_pressed("ui_right"): #when the right arrow is pressed: current += 1 #go to the next section
The error message received is "Error at (19,1) Unindent doesn't match the previous indentation level."
Line 19:Unindent doesn't match the previous indentation level.
-
Thankfully your error message seems to give plenty of information about it. My guess is that you need to select the lines after 19 and indent them (by pressing tab).
Remember: All code inside a function needs to have the same indentation or else the computer will struggle to understand it. Indent is the spaces right before each line.
γγfor example, this text is indented because it is slightly to the right. -
The following script is now in place but another error message is displayed.
The error card is now, "Error at (11,9): identifier "timer" not declared in the current scope. I tried to play about with it. But it did not resolve it.
extends RichTextLabel
@export var texts: PackedStringArray #holds all the sections of text. @export lets you edit it in the inspector.
var current = 0 #a number variable to keep track of which section you are on.func _ready():
visible_ratio = 1
current = 0func _process(delta):
timer += delta #delta is how many seconds elapsed since the last time the code was run. It might be a bit confusing at first but this code is just to make the timer actually count like a timer.if timer >= 10: #when the timer reaches 10 seconds, reset the timer to 0, and go to the next section. timer = 0 current += 1 #same code as before visible_ratio = 0.01 visible_ratio += delta * 0.01 #scrolling text = texts[current] #set the text to the correct section, depending on the variable "current" if visible_ratio == 1: #resetting scrolling after it reaches the bottom visible_ratio = 0 if Input.is_action_just_pressed("ui_right"): #when the right arrow is pressed: current += 1 #go to the next section visible_ratio=0 #reset the scrolling if current >= texts.size(): #OPTIONAL CODE: checking if it already went to the last section current =0
-
"Not declared in the current scope" simply means that the variable couldn't be found.All you need is "var timer = 0" near the top of the code. The top area of the script should look like this:
extends RichTextLabel @export var texts: PackedStringArray var current = 0 var timer = 0
-
Morning, I entered that and the script was fine with no errors visible. However, when you go to run it. The text does not appear at all ?.
extends RichTextLabel
@export var texts: PackedStringArray #holds all the sections of text. @export lets you edit it in the inspector.
var current = 0 #a number variable to keep track of which section you are on.
var timer = 0func _ready():
visible_ratio = 1
current = 0func _process(delta):
timer += delta #delta is how many seconds elapsed since the last time the code was run. It might be a bit confusing at first but this code is just to make the timer actually count like a timer.if timer >= 10: #when the timer reaches 10 seconds, reset the timer to 0, and go to the next section. timer = 0 current += 1 #same code as before visible_ratio = 0.01 visible_ratio += delta * 0.07 #scrolling text = texts[current] #set the text to the correct section, depending on the variable "current" if visible_ratio == 1: #resetting scrolling after it reaches the bottom visible_ratio = 0 if Input.is_action_just_pressed("ui_right"): #when the right arrow is pressed: current += 1 #go to the next section visible_ratio=0 #reset the scrolling if current >= texts.size(): #OPTIONAL CODE: checking if it already went to the last section current =0
Any idea why this is happening ?
-
I do note in the "STack Trace" that a error message "Invalid get index '4' (on base: 'PackedStringArray').
-
I might have some suspicions as to why it doesn't work, but the text is hard to read. Could you please send an image of the entire screen? I want to take a look at the line spacing and also the inspector.
-
I cannot seem to upload files without an error message. I am trying all different ways to upload the file including file types.
-
nodebb-plugin-storj-upload :: The Access Key Id you provided does not exist in our records.
keeps coming up when I attempt this