This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

End a proc

Old posts that have not been replied to for several years.
Locked
s
sege

Post by sege »

How do I end a proc? I'm calling proc 'do:pwd:check' and if something goes wrong in that proc I'd like to end the script. But as it is now it goes back to the proc 'msg:get:memos' and goes on.

Sure, I can solve it in msg:get:memos-proc, but I'm gonna call do:pwd:check from 10 different procs with msg:memo:del and ****.

So, how do I end do:pwd:check? I did try 'exit', and sure, it ends, but a little bit too much. =)
s
sege

Post by sege »

if {[do:pwd:check $lowercasenick $text] == 0} {
return 0
}

Is my solution right now, any better ideas?
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

yes, thats exactly how its done. that is the fundamental logic behind conditional function programming languages. your syntax could be inproved slightly though, ie

if {![do:pwd:check $lowercasenick $text]} {
return 0
}

(this works because if is really tests against integers, evaluating false for 0 and true for everything else, so if do:pwd:check returns 0, the above if evaluates to if {!0} which is if {1} ).

returning 0 on faliure is often seen as bad form, as tradionally a return code of 0 is for ok, but this has no real operational implications.

there are other ways of breaking out of the controlling function that calls a proc without conditional calls, but its bad programming form to do so (look up the syntax on the return command in the tcl docs if you wanna find out how). The only time I can think of that it would ever be needed to throw an exception break would be in highly optimized code, where you cant afford the cpu time an if{} would take (and such code is notoriously difficult for maintanance work).
Locked