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 : Saturday, September 7, 2019 1:51:25 AM(UTC)
adyy

Rank: Member

Reputation:

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

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

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
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
}
Rob  
#3 Posted : Saturday, September 7, 2019 2:50:26 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
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 {}
Rob  
#4 Posted : Saturday, September 7, 2019 2:57:30 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
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.
adyy  
#5 Posted : Saturday, September 7, 2019 3:05:27 AM(UTC)
adyy

Rank: Member

Reputation:

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

Was thanked: 1 time(s) in 1 post(s)
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.