Rank: Member
Groups: Approved
Joined: 8/25/2019(UTC) Posts: 20 Was thanked: 1 time(s) in 1 post(s)
|
StrokesPlus.net prompts the "return" error in the following sample code. Would you tell me how to write the correct statement? Code:
if(...)
{
...
}
else
{
return;
}
...
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
You're not within the context of function in a normal script, so there's nothing from which to return. You can create a function with return statements and call the function, like: Code:test();
function test() {
if(1 == 0) {
//nothing
} else {
return;
}
}
Or just use variables to control flow: Code:var bContinue = true;
if(...) {
...
} else {
bContinue = false;
}
if(bContinue) {
//do more stuff
}
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
You could also wrap the code in a try/catch and throw an error...but that seems like a bit much Code:try {
if(1 == 0) {
//nothing
} else {
throw "Something went wrong!";
}
sp.MessageBox("This will not be reached", "Unreachable");
} catch {}
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
Ultimately, there's a way to structure the code in a way that doesn't require a return. If you post your script, I can give you a refactored version to illustrate this.
|
|
|
|
Rank: Member
Groups: Approved
Joined: 8/25/2019(UTC) Posts: 20 Was thanked: 1 time(s) in 1 post(s)
|
The problem has been solved. Thank you very much for your help.
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close