- Home /
Show Debug logs in return method
I have this code
int chck2nddblelist()
{
int s2ndrandno = Random.Range(0, 3);
Debug.Log("s2ndoublist2: " + s2ndrandno);
return s2ndrandno
}
But everytime I call my code the debug doesn't show. Is this a normal behaviour in return method if it is how to show the debugs.
Answer by ElijahShadbolt · Nov 28, 2016 at 12:23 AM
It looks like you're trying to return the function again, instead of returning s2ndrandno. This means the code will get stuck on that function for all eternity until it crashes.
You could try changing line 6 to show this:
return s2ndrandno;
Sorry bro typo error. Thnx for pointing it out. but it's s2ndrandno in my code.
It might be somewhere else in your code. $$anonymous$$aybe it never gets called. It works fine for me, in the script below.
using UnityEngine;
public class Test : $$anonymous$$onoBehaviour
{
private void Awake()
{
Debug.Log(chck2nddblelist());
}
int chck2nddblelist()
{
int s2ndrandno = Random.Range(0, 3);
Debug.Log("s2ndoublist2: " + s2ndrandno);
return s2ndrandno;
}
}
Answer by aditya · Nov 28, 2016 at 05:13 AM
You are missing semi-colon in return section
return s2ndrandno;
and you can try adding ToString() in Debug section
Debug.Log("s2ndoublist2 : " + s2ndrandno.ToString());
Your answer