- Home /
error CS0161: not all code paths return a value
Idk what I did wrong. I've got code with "sNumber". If sNumber is equal to 1 something happens, if 2/3/4/5/6 something different. If my sNumber option is finished it change snumber to 0 what starts xWP. Check this code:
IEnumerator xWP()
{
int i;
i = Random.Range (1, 6);
sNumber = i;
}
There's something wrong. Whats wrong?
liczbaZmienna controls what actions to perform. At the end of each of them there's StartCoroutine and it starts when you reach the appropriate point. IEnumerator should draw a new activity.
The error says that a function must return a value, and some paths of this functions (like in some "if" or "else" statements), it does not.
Uh... I think you may be misunderstanding me. I am not going to spend any time reading about methods, their signatures, or return values. I already know about them.
I suggest that you read about those things, otherwise program$$anonymous$$g is going to be very difficult for you.
@Habitablaba. That response cracked my up. It surprising how many people come on this site, make no contributions, and expect us to solve all there problems.
Why should I know what I'm talking about, when some other random guy on the internet does? :)
Answer by Kiwasi · Sep 30, 2014 at 11:20 PM
IEnumerator is the return type for a coroutine. Because of the nature of their implementation coroutines must be implemented over multiple frames. You can fake this like so.
IEnumerator xWP(){
int i;
i = Random.Range (1, 6);
sNumber = i;
yield return null;
}
Alternatively if you did not intend to write a coroutine then change the return type to void
void xWP() {
int i;
i = Random.Range (1, 6);
sNumber = i;
}
Answer by bubzy · Sep 30, 2014 at 11:22 PM
try this
IEnumerator xWP()
{
int i;
i = Random.Range (1, 6);
sNumber = i;
yield return null;
}
if you specify a type in the function declaration, unity(or any other complier) will require a return value of that type (or null)
so
int onePlusOne()
{
int answer;
answer = 1+1;
}
would generate your error, but
int onePlusOne()
{
int answer;
answer = 1+1;
return answer;
}
would work correctly
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
; expected. Insert a semicolon at the end. 1 Answer
Script error help! 1 Answer
Scripting error #2! 2 Answers