Rainbow Text

How do I make it so that the text “What is your name?” is rainbow when printed into console?

Try using

MsgC - I’ll try to make a rainbow text function for that if you want since I’m bored (hint - try using

HSVToColor)

Sure thing

Try something like this:



local function PrintRainbow( text )

	local tab = {} -- create a new table to store some stuff that needs to be passed to the MsgC function
	
	for i = 1, #text do -- do a loop for all the letters of the text
	
		local c = HSVToColor( i * 20 % 360, 1, 1 ) -- set the color as the letter we're up to times 20 (change 20 to be higher or lower depending on how much you want the rainbow to be rainbow)
		
		table.insert( tab, c ) -- insert the color into the table
		
		local letter = string.sub( text, i, i ) -- this gets a single letter from the string
		
		table.insert( tab, letter ) -- insert the single letter into the table
		
	end

	table.insert( tab, '
' ) -- add a new line to the console, why not

	MsgC( unpack( tab ) ) -- run the function with the unpacked table (this makes it a bunch of varargs)

end

PrintRainbow( "What is your name?" )


How it works is that since the MsgC function only takes varargs, the table needed to be unpacked into varargs using unpack, but before that, stuff needed to be inserted into the table, such as the color the text should be (which is caused to be rainbow by changing the hue argument of ColorToHSV), and the text (which is a single letter, retrieved by the string.sub bit). This stuff was inserted through the use of the ‘for’ loop, which simply goes through every letter of the string doing the thing above.

I know this is a really awful explanation, but if you look at the wiki pages for all those things, it might make more sense

Thank you.