JS - Cycling problem?

Hi, I have two functions. One is for Login and the second one is for Register… Please can anyone help me with that? Error is:
BCE0070: Definition of ‘Main.Register()’ depends on ‘Main.Login()’ whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.

function Login() {
    var form = new WWWForm();
    form.AddField( "myform_hash", hash );
    form.AddField( "myform_nick", formNick );
    form.AddField( "myform_pass", formPassword );
    var w = WWW(URLlogin, form);
    yield w;
    if (w.error != null) {
        print(w.error);
    } else {
        if(w.text.Contains("Success")){
            prihlaseni = false;
            vyber = true;
          
            PlayerPrefs.SetString("Username", formNick);
            PlayerPrefs.SetString("Password", formPassword);
          
            words = w.text.Split(","[0]);
        }else{
            Register();
        }
        w.Dispose();
          
        formNick = "";
        formPassword = "";
    }
}

function Register() {
    var form = new WWWForm();
    form.AddField( "myform_hash", hash );
    form.AddField( "myform_nick", formNick );
    form.AddField( "myform_pass", formPassword );
    var w = WWW(URLregister, form);
    yield w;
    if (w.error != null) {
        print(w.error);
    } else {
        if(w.text.Contains("Success")){
            PlayerPrefs.SetString("Username", formNick);
            PlayerPrefs.SetString("Password", formPassword);
          
            formNick = PlayerPrefs.GetString("Username");
            formPassword = PlayerPrefs.GetString("Password");
  
            if(formNick !== ""){
                if(formPassword !== ""){
                    Login();
                }
            }else{
                prihlaseni = true;
            }
        }
        w.Dispose();
    }

    formNick = "";
    formPassword = "";
}

There’s a potential loop inside these two functions (line 21 → register, line 49 ->login) and unity doesn’t like these kind of loops

I know, it’s logic… But is there any option how to do it?

It’s not that “Unity doesn’t like these kind of loops”. Recursive logic is common in games, and many functions rely on it.

The problem here is inferred return types. Normally, a function has a return type - a function that adds two integers will probably return an integer, and the JS compiler is smart enough to infer this from context:

function TwoAndTwo() {
return  2 + 2; //"2 + 2" is an int, therefore the return type of this function must be int! I'm a smart compiler.
}

function AlsoTwoAndTwo() {
return TwoAndTwo(); //I've previously figured out that TwoAndTwo return an int, so this function must also return int!
}

The problem is that when function A needs to know function B’s return type, and function B needs to know function A’s return type, it can’t figure it out.

function A() {
return B();
}
var x = 0;
function B() {
x++;
if (x < 3) return A();
else return 0;
}

(nevermind how nonsensical the logic here is)

So you have to explicitly tell the compiler at least one of their return types. This usually comes up, as it has here, with coroutines. Coroutines have the IEnumerator type, which in JS is pretty much always inferred, unless in the case of these recursive loops. Try this on one or both of the functions:

function A() : IEnumerator {

Thank you for explanation… I made it another way, but your way looks better… My way:

function CallFunction(name : String){
     if(name == "Login"){
          Login();
     }
     
     if(name == "Register"){
          Register();
     }
}