Void return statement

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Skeevitch

I’m a novice to coding and I’m watching a youtube video on how to make a shader in Godot, but along the process I received a text message error stating, “expected one return statement from a non void value.” Can someone please help?

  shader_type canvas_item;
    
    uniform vec3 color = vec3(0.33,0.15,0.82);
    
    
    float rand(vec2 coord){ 	return fract(sin(dot(coord, vec2(56,78)) *
    1000.0) * 1000.0); }
    
    float noise(vec2 coord){ 	vec2 i = floor(coord); 	vec2 f = fract(coord); 	 	float a = rand(i); 	float b = rand(i + vec2(1.0,
    0.0)); 	float c = rand(i); + vec2(1.0, 0.0); 	float d = rand(i); +   vec2(1.0, 0.0); 	}

it’s in this section where I am receiving the error.

void fragment(){
    COLOR = vec4(color, rand(UV));
}
:bust_in_silhouette: Reply From: njamster

You declared a function called noise returning a variable of type float. However, in the code for that function you never return anything (i.e. you return void).

So either change the return type of your function:

void noise(vec2 coord) {
    // ...
}

or make sure you actually return a float value:

float noise(vec2 coord) {
    // ...
    return 0.0;
}

thank you so much!

Skeevitch | 2020-07-18 19:48