egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED] return/continue

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Wed May 20, 2009 10:57 am    Post subject: [SOLVED] return/continue Reply with quote

i need some help or hint again Smile

this time its about return 0/return 1 or something else like that. until now i used to use return 0 if i wanted a script to end but sometimes i only want to escape from the if and continue with the rest of the script. is there a way to do that?

in example:

Code:

f { $chan == "#chan1" } {
   if { $nick == "notwantednick" } {
      fail
      escape that if and continue with if2, dont stop parsing the rest of the script
   }
}
if2 { ... } {
   code here
}


i hope i got it all right by explaining so you guys know what im after ^^

edit:

i might also want to add that i tried playing around with break, return 0, return 1 and continue


Last edited by raider2k on Wed May 20, 2009 1:37 pm; edited 1 time in total
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed May 20, 2009 11:14 am    Post subject: Reply with quote

Don't use either...

When using if, the first parameter is the conditional to test, the second the code to execute if the conditional was true. The optional third would be what to execute if the conditional was false. There is no need to "escape" from those code-blocks.. once they reach the end, the processing continues with the first command after the if conditional.

Code:
...
if {$chan == "#chan1"} {
  if {$nick == "notwantednick"} {
    #executed if $chan == #chan1 and $nick == notwantednick
  } {
    #executed if $chan == #chan1 and $nick != notwantednick
  }
}
if {$::botnick == "nisse"} {
  #executed if bot's nick is nisse, regardless of $chan or $nick...
}
Notice how I don't use any return, break, or continue there. Instead I let each code-block run to it's end.

Return has the sole purpose of stopping a proc from running, and returning a value to whatever called the proc in the first place. Whether you use 0 or 1 or anything else won't affect this behaviour, some eggdrop bindings do care for the returned value, but that's outside the scope of this discussion.

Continue is used in loops, such as for, foreach, and while. It instructs the loop controller to halt the current iteration immediately, and proceed to the next iteration.

Break is used in loops, such as for, foreach, and while, as well as the conditional construct switch It instructs the controller to halt the current iteration immediately, and return, allowing the next command in the script to be executed.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Wed May 20, 2009 11:39 am    Post subject: Reply with quote

nml375 wrote:

Code:
...
if {$chan == "#chan1"} {
  if {$nick == "notwantednick"} {
    #executed if $chan == #chan1 and $nick == notwantednick
  } {
    #executed if $chan == #chan1 and $nick != notwantednick
  }
}
if {$::botnick == "nisse"} {
  #executed if bot's nick is nisse, regardless of $chan or $nick...
}
Notice how I don't use any return, break, or continue there. Instead I let each code-block run to it's end.


alright, was thinking of an answer that would tell me to do it otherwise.
so theres no way like a goto or similar?

because sometimes i need the current if or a certain part to end and need another one to continue - as it happens sometimes in pubm's
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Wed May 20, 2009 1:06 pm    Post subject: Reply with quote

Pretty much any goto-logics can be replaced with proper conditional blocks..

Either by having consecutive conditionals, nested conditionals, or both.

Ie:
Code:
if {case1} {
 puts stdout "case1 is true"
 if {case2} {
  puts stdout " in addition, case2 is also true"
 }
 puts stdout "end of case1 block
}

This would be a perfectly fine replacement for the pseudo-code below:
Code:
if {case1} {
 puts stdout "case1 is true"
 if {not case2} {
  goto end
 }
 puts stdout " in addition, case2 is also true"

 end: puts stdout "end of case1 block"
}


Edit: And no, there is no "goto" function in tcl
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Wed May 20, 2009 1:37 pm    Post subject: Reply with quote

well thanks
im sure im going to figure it out though how to handle it the way i want it to be in combination with ur advices Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber