ERROR:bad argument #1 to 'set_color' (userdata expected, got string) (SOLVED)

Hi,

I have a node which is just a black rectangle with the same size as the screen.
The purpose of above node is to make screen transitions(fade to black/fade from black).

I can’t seem to change the alpha of the above node, console spits out the below error:

function init(self)
	-- Add initialization code here
	-- Remove this function if not needed

	msg.post(".", "acquire_input_focus")
	
	go.set("#FAS-Statue", "scale.x", 0.65)
	go.set("#FAS-Statue", "scale.y", 0.65)

	gui.set_color( "#ScreenFadeNode", vmath.vector4(1, 1, 1, .5) )
--  ^-- ERROR:bad argument #1 to 'set_color' (userdata expected, got string)
	
--	go.set_position( vmath.vector3( 0, 0, 0 ), "#FAS-Website" )
--	go.set_position( vmath.vector3( 0, 0, 3 ), "#ScreenFade" )
--	go.set( "#ScreenFade", "tint", vmath.vector4( 1, 0, 0, .5) )

end

What am I doing wrong?
Thanks!

J.

Gui calls belong in gui scripts. You cannot use functions from the gui namespace in game object script components.

And pretty much all gui functions operate on nodes, not url:s or id:s.

See https://www.defold.com/manuals/gui/

Hi,

Got it almost working…

My issue now is the GUI text is ABOVE the ScreenFade sprite?
I messed around with the ScreenFade’s Z-axis but has no effect?

J.

Yes, that is the behavior of the default render script.

Well, how can I fix the above issue?
The “ScreenFade” sprite must be above all other things to work.
Let me know, thanks!

J.

You can change the renderscript to draw the sprite on top of everything else. You need to change material tag though. This is a bit advanced. Perhaps use labels instead of text nodes?

1 Like

Thanks, I have fade to black and fade from black screen transitions working now…
…Next is switching screens which is covered in the “Color Slide” tutorial…

J.

2 Likes