Background music script gives errors

My background music script is made to play one song then the other and so on infinitely but it gives me errors and doesn’t work.

Here is the script:

#pragma strict

var sandstorm1 : AudioClip;
var sandstorm2 : AudioClip;

function Start ()
{
    PlaySandstorm();
}

function PlaySandstorm()
{
    audio.PlayOneShot(sandstorm1, 0.3);
    yield WaitForSeconds(210);
    PlaySandstorm2();
}

function PlaySandstorm2()
{
    audio.PlayOneShot(sandstorm2, 0.3);
    yield WaitForSeconds(80);
    PlaySandstorm();
}

My errors are:

Assets/Scripts/Music.js(22,9): BCE0070: Definition of ‘Music.PlaySandstorm2()’ depends on ‘Music.PlaySandstorm()’ whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.

Assets/Scripts/Music.js(22,9): BCE0070: Definition of ‘Music.PlaySandstorm2()’ depends on ‘Music.PlaySandstorm()’ whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.

I don’t know jscript so I cant tell if you’re calling PlaySandstorm 1 and 2 as coroutines or not. Unless coroutines, afaik yield will not work properly even on jscript.

Also, if they are not as coroutines, your two methods will indeed theoretically result in an infinite loop till stack overflow (in practice, they will stop at the yield, since they won’t be able to automatically “resume” the execution), so the error messages makes sense.

Edit: I fast-read the manual page and missed the part where it answers my question. No need to call start coroutine on jscript. So I’d guess your solution would be a small state machine and a single method with a loop

Edit2: “Explicitly declare the type of either one to break the cycle.”. Try explicitly calling them as coroutines before making major changes.