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.

namespace, foreach - problem

Help for those learning Tcl or writing their own scripts.
Post Reply
c
caramba
Voice
Posts: 2
Joined: Sat Feb 21, 2009 12:35 pm

namespace, foreach - problem

Post by caramba »

Hi everyone

simple script:

Code: Select all

bind pub - !do do_proc

proc do_proc {unick uhost uhand uchan uarg} {
        namespace eval $unick {
                set nickname [lindex [split [namespace current] ":"] 2]

                set letters {a b c d e f g}

                foreach letter [split $letters] {
                        putquick "PRIVMSG $nickname :$letter"
                }
        }
}
We have on one channel, user1 and user2.

When user1 type !do script is writing letters, yeah that's okey.
Now, after 2 seconds user2 is typing !do too and the problem begins..

user1, pm:

Code: Select all

a
b
c
d
e
f
g
user2, pm:

Code: Select all

d
e
f
g
a
b
c
Can someone help with that?
How to make this to work?
I mean how to make this to "parallel"...

If i tried without "foreach", just some simple incr var 1 inside namespace, it was good.

I could make !do on first and second user and all were good, numbers were ok for both of them.
I don't know why its not working with foreach/for.

Thanks!

P.S
Sorry for my bad english.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

That's odd, very odd..

Since eggdrop operates in a non-threaded fashion, each binding will block until completed, so the second !do won't be processed until the first one is actually completed.

This would actually point a finger at the queue-system, as putquick does not send the command instantly, but places it in a queue to be send as soon as possible. However, this breaking on foreach but no other loop-constructs points in other directions.

Do you think you could add som putlog's in there, especially within the loop logging the message to be queue'd, and anything else possibly of value?
Also, could you post details on version of eggdrop and tcl?
NML_375
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

damn, i have the same problem in many scripts.

for example, we have text file:
row
row2
row3

etc etc.

And now, we have a script with:
bind pub - !test foreach_proc

...
foreach line [file data] {
puthelp "privmsg $nick :$line"
}
...

Its working good for one person.
Problem begins when 2 or more ppl is using this command in one time.

Some problem with eggdrop queue, don't know.
I tried to do my own queue etc. but no effect (with timers, user by user).

Script is making this foreach pretty fast (whole data is landing in command queue) and after, script is going to next line when bot outputing messages and im getting mess.

user1
row
row2
row3

user2
row2
row
row3

or something

P.S
Many scripts on net have this problem. (scripts which printing many lines of data and can be used by 2 or more ppl in the same time by some command)
I think my last (and other ;/) two scripts from request too.
I mean football-table/profile scripts.

It funny cause i dont remember how long i'm programming for eggdrop, all other scripts are working ok, but this "parallel" output is horible.
Last edited by tomekk on Tue Feb 24, 2009 7:23 pm, edited 6 times in total.
c
caramba
Voice
Posts: 2
Joined: Sat Feb 21, 2009 12:35 pm

Post by caramba »

Hey

I tested it on TCL 8.4.12, 8.5.5 with eggdrop 1.6.18.
The same problem on both.

Like tomekk said, it's something wrong with queue.
I don't know how to fix it.
I changed in config "max-queue-msg" no effect.
I tried puthelp/putquick/putserv - nothing.

There is no possibility to send more data (line by line) to 2 or more users in the same time?

Regards
M.

P.S
If i made putlog instead put* i got messages okey, i mean:

a
b
c
d

a
b
c
d
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Have you ever thought, maybe this is related to latency?

Instead of running your tests where lag (latency) can cause messages to fall out or order. Foreach executes instantaneously as it does the putserv. All of this happens so fast, lag is certainly a factor when reading reply times spewed onto irc. Instead of using that putserv use a putlog where lag cannot come in play, and you will see lag is the culprit.
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

lag, dont think so

iim testing it on myown localhost ircd server

i found smth else, this script:

Code: Select all

bind pub - !test test_proc

proc test_proc { nick uhost hand chan arg } {
        set blah [open "ble.txt" r]
        set all [read $blah]
        close $blah

        foreach line [split $all "\n"] {
                puthelp "PRIVMSG $nick :$line"
        }
}
ble.txt:

Code: Select all

aaaa
bbbb
cccc
dddd
eeee
ffff
gggg
hhhh
User1 is making !test on chan, after when bot prints 1st line to user1, user2 is making !test too:

user1 output:
aaab
bbbb
cccc
ddd
eeee
ffff
gggg
hhhh

user2 output:
bbbb
cccc
ddd
eeee
ffff
gggg
hhhh
aaaa

it's messy, ok

now, if i change script:

Code: Select all

bind pub - !test test_proc

proc test_proc { nick uhost hand chan arg } {
        set blah [open "ble.txt" r]
        set all [read $blah]
        close $blah

        foreach line [split $all "\n"] {
                puthelp "PRIVMSG $nick :$line [queuesize]" #extra [queuesize] here
        }
}
And the same situation, user1 test1, after first line, user2 !test, output:

user1:
aaaa 0
bbbb 1
cccc 2
dddd 3
eeee 4
ffff 5
gggg 6
hhhh 7
8

user2:
aaaa 8
bbbb 9
cccc 10
dddd 11
eeee 12
ffff 13
gggg 14
hhhh 15
16

now its cool, any solution? :)
tested couple of times
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Could you tell me how you set these settings?

Code: Select all

# Allow identical messages in the mode queue?
#set double-mode 

# Allow identical messages in the server queue?
#set double-server 

# Allow identical messages in the help queue?
#set double-help 
NML_375
User avatar
tomekk
Master
Posts: 255
Joined: Fri Nov 28, 2008 11:35 am
Location: Oswiecim / Poland
Contact:

Post by tomekk »

I have it on default 0, but i tried to change it to 1, no effect.
Post Reply