Linebreak Problems (SOLVED)

I’ve been going through older code and switching it out with more efficient processes. I’ve run into a bit of trouble, though, and can’t get the linebreaking mode to work on my GUI node.

function defChat(self,node)
	gui.set_size_mode(node,gui.SIZE_MODE_MANUAL)
	gui.set_size(node,vmath.vector3(self.lineWidth,chatProperties.height,0))
	gui.set_parent(node,gui.get_node("Chatbox"))
	gui.set_line_break(node,true)
	gui.set_font(node,self.font.name)
	gui.set_pivot(node,gui.PIVOT_W)
	gui.set_color(node,chatColor)
	incline = 0
	print("CHAT NODE SIZE: ".. gui.get_size(node))
end

The node is given it’s definitions with this function. I later write a message on the node as to was it is supposed to display. I have it run on a stamping function which quickly, but noticeably, prints out the letters from the original message and adds them to the node. Note, this text is applied to the node after I tell the node it should linebreak. I’m not sure if this matters, but I tested it and it seems it doesn’t work either way.

The node is given a width of around 300 pixels with self.lineWidth. Every time I write a message larger than that, linebreak seems to be broken. The messaging system works perfectly, except for when I write large messages. It’s supposed to linebreak them as they get larger in the stamping process, and then achieve enough space for it to nest in height-wise. It is currently being printed out in one large string, exceeding the width of the node containing it, instead of multiple lines.

Correct me if I’m wrong, but the linebreaking function takes into account the size of the node and linebreaks the text to remain inside it’s width, right? Or does it also take into account the height of the node?

This is correct.

I tried myself like this:

function init(self)
	local text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis hendrerit dui vel tristique feugiat. Integer ut neque dui. In dictum vel mauris porta placerat. Donec in cursus nunc."
	local node = gui.new_text_node(vmath.vector3(), text)
	gui.set_size_mode(node, gui.SIZE_MODE_MANUAL)
	gui.set_size(node, vmath.vector3(300, 100, 0))

What the hell is going on with the syntax highlighting of this specific piece of code?! (see broken highlighting below) If I have it in a single chunk the highlighting breaks…

	gui.set_parent(node, gui.get_node("box"))
	gui.set_line_break(node, true)
	gui.set_font(node, hash("score"))
	gui.set_pivot(node, gui.PIVOT_W)
	gui.set_color(node, vmath.vector4(0.2, 1.0, 0.4, 1))
end

And this is the .gui scene:

Broken syntax highlighting @sicher and @samuel.nystedt :

function init(self)
	local text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis hendrerit dui vel tristique feugiat. Integer ut neque dui. In dictum vel mauris porta placerat. Donec in cursus nunc."
	local node = gui.new_text_node(vmath.vector3(), text)
	gui.set_size_mode(node, gui.SIZE_MODE_MANUAL)
	gui.set_size(node, vmath.vector3(300, 100, 0))
	gui.set_parent(node, gui.get_node("box"))
	gui.set_line_break(node, true)
	gui.set_font(node, hash("score"))
	gui.set_pivot(node, gui.PIVOT_W)
	gui.set_color(node, vmath.vector4(0.2, 1.0, 0.4, 1))
end

Weird. If I use code fences (```) around the code instead of indentation it works:

	function init(self)
		local text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis hendrerit dui vel tristique feugiat. Integer ut neque dui. In dictum vel mauris porta placerat. Donec in cursus nunc."
		local node = gui.new_text_node(vmath.vector3(), text)
		gui.set_size_mode(node, gui.SIZE_MODE_MANUAL)
		gui.set_size(node, vmath.vector3(300, 100, 0))
		gui.set_parent(node, gui.get_node("box"))
		gui.set_line_break(node, true)
		gui.set_font(node, hash("score"))
		gui.set_pivot(node, gui.PIVOT_W)
		gui.set_color(node, vmath.vector4(0.2, 1.0, 0.4, 1))
	end
1 Like

So it probably has something to do with the fact that I’m developing the text value in my stamp function after defining it? When I create each node it starts out with an empty text value. The text value is filled in over the next second or two, depending on the speed of the stamping function and the length of the text.

This is what my stamping function does:

function stamp(self)
	while self.chatNodes[stamped + 1] == Deleted do
		print("FOUND DELETED NODE ------------------------------------------------------") -- After a certain amount of nodes, the earliest are deleted. This prevents the stamping function from trying to insert text into an empty node, in which case it would throw an error and break.
		stamped = stamped + 1
		let = 0
		total = ""
	end	
	let = let + 1
	maxLet = string.len(msgStrings[stamped + 1])
	local letter = string.sub(msgStrings[stamped + 1],let,let)
	total = total .. letter
	gui.set_text(self.chatNodes[stamped + 1],total) -- This is what makes each stamp visible. The text grows using this repeatedly.
		
	if let >= maxLet then
		print("stamped: " .. total)
		total = ""
		let = 0
		stamped = stamped + 1
		msgStrings[stamped - 1] = nil
		actStamp = false
	end
	if messages > stamped then
		actStamp = true
	end
end

AHA! I found my issue. I was testing by writing a long SINGLE string of gibberish. The automatic linebreak works by shifting the positions of whole WORDS, not single letters. Is there a way to switch this functionality?

If not, could this be a request for added functionality for the linebreak function?

Maybe something like:

function linebreak(node,active,charShift)
     if active then
          if charShift then
               -- linebreak by shifting string by characters, not entire words
          else
               -- linebreak regulary
          end
     end
end

If someone writes random gibberish like I did, it still needs to have a good appearance. This functionality would allow for more precise text fitting. Although, it would remove the “pretty reading” factor, it would make it easier for us to recreate old-style text RPG’s and what-not. Plus, we could always leave charShift as false to have it operate normally.

Ah, yes, it only breaks on words. Long strings will not be broken up. I guess you could implement this yourself if needed.