Error: not all code paths return a value

Hi, i get an error from the compiler: int this function not all code paths return a value

int Roulette(int num){
		int val = Random.Range(0,num);
		for(int i=1; i<=num; i++){
			if(val<i  val>=i-1){
				return i;
			}else{
				return 0;
			}
		}	
	}

Do you see where i’m wrong? It seems to me that all the paths return a value…

int val = Random.Range(0,num);
for(int i=1; i<=num; i++){
if(val=i-1){
return i;
}else{
return 0;
}
}
return 0;

you need to have a return statement under the for loop, because now when num == 0 there will be no return value since the loop doesnt have anything to loop trough.

int Roulette(int num){
		int val = Random.Range(0,num);
		for(int i=1; i<=num; i++){
			if(val<i  val>=i-1){
				return i;
			}else{
				return 0;
			}
		}
return 0;
	}

also, is it your goal to only check the first element in the loop, because right now it always stops at your first element. you might want to remove the else statement in the loop so that it gets the first element where your statement is true, or 0 if the statement is not true on any of the elements.

int Roulette(int num){
		int val = Random.Range(0,num);
		for(int i=1; i<=num; i++){
			if(val<i  val>=i-1){
				return i;
			}
		}	
return 0;
	}

If num = 0 then it won’t get in that for and then it won’t get a return.

Also… What is that code supposed to do?

Shure… i didn’t considered the num=0 situation… Tx
@AcidArrow i’m just messing around learning unity