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.

stop foreach

Old posts that have not been replied to for several years.
Locked
c
crios
Voice
Posts: 2
Joined: Sun Apr 10, 2005 12:59 pm

stop foreach

Post by crios »

Hi,

I have a proc with a

foreach player [split $data] {
...
putserv "PRIVMSG,...."

}

i want to create a stop command

when i say !stop it should stop the foreach because sometimes there are over 100 lines in player
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

create a global var like breakforeach with boolan content (0 or 1).
make a public trigger to set it to 1 and add at the end of the foreach:

Code: Select all

if { $breakforeach } {
  set breakforeach 0
  break
}
if you concern the execution speed of this extra, than dont use ::breakforeach, but add breakforeach to global at the proc start. I tested it on real unix and cygwin, execution is about the half (if it matters for 2ms or 4ms ^^).

the public command could look like:

Code: Select all

bind pub m|m !stop initforeachbreak

proc initforeachbreak {nick uhost hand chan text} {
  set ::breakforeach 1
  return 1
}
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
c
crios
Voice
Posts: 2
Joined: Sun Apr 10, 2005 12:59 pm

Post by crios »

sry i don't understand how i could use that in my script :/

maybe you can make an bigger example?
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

when I think about it... forget the idea, the foreach loop is long done probably before the first line is seen on the channel.
the only solution would probably be to change the putserv to puthelp (i strongly suggest this) and then make following bind:

Code: Select all

bind pub m !stop initforeachbreak

proc initforeachbreak {nick uhost hand chan text} {
  clearqueue help
  return 1
}
I haven't tested it, but it should wipe all pending messages in the help queue (if you would wipe the server or mode queue, you could kill something important).
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Locked