Change Color Of Script Generated Text?(SOLVED)

Hi,

Working on the [About] staff screen today.
We have generated a line of text in a GUI script and it does display on the screen.
We are trying to change the color of above line of text to yellow, but it spits out an error.

Below is relevant code:

function init(self)
	msg.post(".", "acquire_input_focus")
	msg.post("#", "show_level_select")
	self.active = false

	local text_nodes = {}
	table.insert(text_nodes, gui.new_text_node(vmath.vector3(180, 320, 0), "Red Light Racer"))
	gui.set_color( text_nodes[0], vmath.vector3(1.0, 1.0, 0) ) -- <-- ERROR: bad argument #1 to 'set_color' (userdata expected, got nil)
	
end

Any help would be appreciated…
Thanks!

J.

1 Like

Below works:

	TotalNumberOfTexts = 0
	local text_nodes = {}
	text_nodes[0] = gui.new_text_node( vmath.vector3(180+110, 320+20, 0), "TM" )
	gui.set_color( text_nodes[0], vmath.vector3(1.0, 1.0, 0) )
	TotalNumberOfTexts = (TotalNumberOfTexts + 1)
	text_nodes[1] = gui.new_text_node( vmath.vector3(180, 320, 0), "''Red Light Racer''" )
	gui.set_color( text_nodes[1], vmath.vector3(1.0, 1.0, 0) )
	TotalNumberOfTexts = (TotalNumberOfTexts + 1)

J.

1 Like

Arrays (tables indexed by numbers) in Lua start at 1, not 0. That is why you are getting an error (and should say in the error message).

I highly recommend learning the programming language properly before jumping in to making a full game using it. An excellent place to start is here: Lua in Defold.

3 Likes