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.

One result in public, the rest in private

Help for those learning Tcl or writing their own scripts.
Post Reply
r
rubenmb
Voice
Posts: 3
Joined: Sat Apr 15, 2006 3:54 am

One result in public, the rest in private

Post by rubenmb »

Hi everyone,

Here's what i want to do. I have some results from a mysql query, lets say like 10. And right now, i am using a foreach loop to set my variables for each one of the results and output them into one channel. Now what i want to do is output the first result it finds in public, and all the rest in private.
Anyone has an idea on how this could be done?
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: One result in public, the rest in private

Post by user »

Code: Select all

puthelp "PRIVMSG #chan :[lindex $list 0]"
foreach item [lrange $list 1 end] {
	puthelp "PRIVMSG nick :$item"
}
Have you ever read "The Manual"?
r
rubenmb
Voice
Posts: 3
Joined: Sat Apr 15, 2006 3:54 am

Post by rubenmb »

That looks nice. Tks for the reply. But how should it be done if some of the results contain more then one argument in the same string:

Code: Select all

{some text more text}
lindex will result in an output of those words like they were diferent results:

Code: Select all

some
text
more
text
:roll:
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

In your first post you said you used foreach to create some variables... $list in my example would be the list you passed to foreach.
Have you ever read "The Manual"?
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

rubenmb wrote:That looks nice. Tks for the reply. But how should it be done if some of the results contain more then one argument in the same string:

Code: Select all

{some text more text}
lindex will result in an output of those words like they were diferent results:

Code: Select all

some
text
more
text
:roll:
Yeah, and for

Code: Select all

{"some text" "more text"}
lindex will result in
some text
more text
r
rubenmb
Voice
Posts: 3
Joined: Sat Apr 15, 2006 3:54 am

Post by rubenmb »

Yes user your right, i should have posted you some code.
And that way you would see that after calling the foreach i handle each argument of each string in a way
that makes it impossible to use the method you posted,
because its no longer:

Code: Select all

 {some text and more text} {second result text} {and so on}
after my foreach it'll be something like:

Code: Select all

[TAG] Result 1: \002some text and more text\002
for each of the resulted data.

But your help was still very much appreciated, cause basing my self on that
i was able to tweak the script and end up with what i wanted.
I'll explain for the ones that will run into the same problem:

Code: Select all

## instead of looping around the raw data first
## I separated the first result ($n1) from the rest ($nx)

       set n1 [lindex $data 0]
       set nx [lrange $data 1 end]

## then i submited the first result to my proc with type=public

       my_proc $n1 $needed $variables public

## for the rest of the results, and now yes, i use a foreach loop and type=private

       foreach item $nx {
          my_proc $item $needed $variables private
       }

## then on my proc

proc my_proc { item needed variables type }
set this
set that
bla bla
if {$type == "public"} {
     putserv "PRIVMSG $channel :$line"
} else {
     putserv "PRIVMSG $nick :$line"}
}

So thats how i pull it off :D
Again thanks for the help user

regards
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

So basically, you did exactly what user suggested :lol:
Post Reply