Sanjeev 46 Posted May 26, 2014 Report Share Posted May 26, 2014 Fellas? Just wanted to know from your experience with using nested ifs- If I have code like this - multiple nested ifs.. if("") { then { if("") { then { if("") { then { if("") { then { if("") { then { } else { } } } else { } } } else { } } } else { } } } else { }} Does this cause Ubot to be unstable ..?Do I need to limit to how many nested ifs we can use inside our script? I came across this thread.. Its an old thread , but with Ubot - many issues still remain.Thanks. Quote Link to post Share on other sites
the_way 52 Posted May 26, 2014 Report Share Posted May 26, 2014 first thing is to separate your functions from functionality, thats very messy, and poor coding technique Quote Link to post Share on other sites
UBotDev 276 Posted May 26, 2014 Report Share Posted May 26, 2014 I don't think there is a limit to keep UBot stable. Quote Link to post Share on other sites
blumi40 222 Posted May 26, 2014 Report Share Posted May 26, 2014 anyway neested "if" are not a good codingstyle use elseif and/or set parameters likeif(bla=true)then{#parameter=$true}if(#parameter=$true)then{do what u have to do}and so on 1 Quote Link to post Share on other sites
Sanjeev 46 Posted May 26, 2014 Author Report Share Posted May 26, 2014 first thing is to separate your functions from functionality, thats very messy, and poor coding technique anyway neested "if" are not a good codingstyle use elseif and/or set parameters likeif(bla=true)then{#parameter=$true}if(#parameter=$true)then{do what u have to do}and so on Thanks for your reply - but I find in some circumstances nested ifs become unavoidable,also, Ubot does not appear to have a clean way to return back - if you are inside a 'loop' node? I don't think there is a limit to keep UBot stable. Tadej, I take it you mean multiple nested ifs will not make Ubot Unstable -no matter how deep the nesting? Thanks. Quote Link to post Share on other sites
UBotDev 276 Posted May 26, 2014 Report Share Posted May 26, 2014 Thanks for your reply - but I find in some circumstances nested ifs become unavoidable,also, Ubot does not appear to have a clean way to return back - if you are inside a 'loop' node? Tadej, I take it you mean multiple nested ifs will not make Ubot Unstable -no matter how deep the nesting? Thanks.No, it shouldn't be a problem, although as other guys say, it's not a good practice to use nesting extensively. Quote Link to post Share on other sites
Sanjeev 46 Posted May 26, 2014 Author Report Share Posted May 26, 2014 No, it shouldn't be a problem, although as other guys say, it's not a good practice to use nesting extensively. Thanks. Quote Link to post Share on other sites
Marton 48 Posted June 15, 2014 Report Share Posted June 15, 2014 Thanks for your reply - but I find in some circumstances nested ifs become unavoidable,also, Ubot does not appear to have a clean way to return back - if you are inside a 'loop' node? If you use the command "return" it will return to the beginning of the loop. If you use "return" in a "loop while" it will return back to the beginning and check the condition. 1 Quote Link to post Share on other sites
blumi40 222 Posted June 15, 2014 Report Share Posted June 15, 2014 If you use the command "return" it will return to the beginning of the loop. If you use "return" in a "loop while" it will return back to the beginning and check the condition.??? Example pls !!! Quote Link to post Share on other sites
Marton 48 Posted June 15, 2014 Report Share Posted June 15, 2014 ??? Example pls !!!Hi Blumi, These are not necessarily useful examples, I created them just to demonstrate the concept: testing()alert("Counter: {#counter}")define testing { set(#counter, 0, "Global") loop(5) { increment(#counter) return("") alert("Commands below the return won\'t get excecuted. You will not see this message when running the script.") }} As you can see even though there is a return command, the bot will just jump back to the beginning of the loop = there will still be 5 iterations, but commands below return won't get executed (obviously you could add an if statement for the return command). Similar example with loop while: testing()alert("Counter: {#counter}")define testing { set(#counter, 0, "Global") loop while($comparison(#counter, "<", 5)) { increment(#counter) return("") alert("Commands below the return won\'t get excecuted. You will not see this message when running the script.") }} The return command will jump back (return) to check the condition, and only truly exit the loop when the given condition is met. So 5 iterations here as well. The problem with these is that the return will also exit from the define, so commands after the loop in the same define won't get executed. So this is not the best coding habit either, but could be used in some cases. Anyway, this is how return works when used in loop or loop while statements. Quote Link to post Share on other sites
blumi40 222 Posted June 15, 2014 Report Share Posted June 15, 2014 Absolute new for me!as i know $return is for give back a val in a function and where is the differnce betweentesting()alert("Counter: {#counter}")define testing { set(#counter, 0, "Global") loop while($comparison(#counter, "<", 5)) { increment(#counter) return("") alert("Commands below the return won\'t get excecuted. You will not see this message when running the script.") }} and testing()alert("Counter: {#counter}")define testing { set(#counter, 0, "Global") loop while($comparison(#counter, "<", 5)) { increment(#counter) }} i see no benefit on it Quote Link to post Share on other sites
Marton 48 Posted June 16, 2014 Report Share Posted June 16, 2014 Absolute new for me!as i know $return is for give back a val in a function As with most programming languages, return can also be used without value, not just in functions, but in command defines as well. It can be used to "return" from a define (exit) back to Main. That is used by many programmers, because there are cases when it's cleaner to use return to exit from a define instead of using IF statements for everything in the define. Of course -depending on your code- using lots of returns can be considered as bad coding habit too. So the main purpose of knowing what I just demonstrated with loop and loop while, is to keep in mind that the return will not immediately exit the current command define (if that's what you wanted in your code) like it would normally do, it will simply go back to the beginning of the loop. So if you're using a return, keep all that in mind if it happens to be in a loop (or don't use it in a loop). 1 Quote Link to post Share on other sites
blumi40 222 Posted June 16, 2014 Report Share Posted June 16, 2014 thx martoni thing i need a better example to understand this!so ...next time u coding and u use it thing about me if u work with a return outside a func Quote Link to post Share on other sites
Marton 48 Posted June 16, 2014 Report Share Posted June 16, 2014 thx martoni thing i need a better example to understand this!so ...next time u coding and u use it thing about me if u work with a return outside a func Marton, Just like Blumi, I thought the RETURN returns a value of something after reading about it in the pdf tutorials but I never really quiet understood how to use it.And, if it can also exit the script out of loops and DEFINES like you say then great!Show us some more examples when you can. Ok ? Cheers! Here's what you need to know: return will EXIT the function/custom command immediately, returning to the caller. It doesn't necessarily need a value either. You could have something like this in your custom command (define) anywhere: if("condition") { then { return("") }} So you could have many commands before and/or after this IF statement. If the condition is met, it will exit immediately, but if not, it will just go on with the rest of the code in the define. Yes, this could be solved with conditional statements instead of having a return in the middle of your define, but sometimes visually this can be a better choice, rather than having many long, nested IFs in your code. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.