StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
adyy  
#1 Posted : Friday, September 6, 2019 7:51:25 PM(UTC)
adyy

Rank: Member

Reputation:

Groups: Approved
Joined: 8/25/2019(UTC)
Posts: 20
China

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;
}
...
Rob  
#2 Posted : Friday, September 6, 2019 8:42:09 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 433
United States

Thanks: 5 times
Was thanked: 84 time(s) in 72 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
}
Rob  
#3 Posted : Friday, September 6, 2019 8:50:26 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 433
United States

Thanks: 5 times
Was thanked: 84 time(s) in 72 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 {}
Rob  
#4 Posted : Friday, September 6, 2019 8:57:30 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 433
United States

Thanks: 5 times
Was thanked: 84 time(s) in 72 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.
adyy  
#5 Posted : Friday, September 6, 2019 9:05:27 PM(UTC)
adyy

Rank: Member

Reputation:

Groups: Approved
Joined: 8/25/2019(UTC)
Posts: 20
China

The problem has been solved.
Thank you very much for your help.
Users browsing this topic
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.