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.

Binds to msg and pub allow scripts to interact - SOLVED

Help for those learning Tcl or writing their own scripts.
Post Reply
s
silenus
Voice
Posts: 10
Joined: Sat Jan 05, 2008 12:37 pm

Binds to msg and pub allow scripts to interact - SOLVED

Post by silenus »

I have had trouble formulating a good subject line for this question, but it comes down to the fact that I must have a fundamental misunderstanding of binds. Can anyone explain to me please what I am doing wrong here? I have written two scripts (mychann.tcl and mychann_ops.tcl). As you might expect, mychann.tcl runs in #mychann and mychann_ops.tcl runs in #mychann_ops. The same bot is present in both channels.

The scripts do essentially the same thing and have a lot of procs in common, but they have different binds. mychann.tcl is bound to msg like this :

Code: Select all

bind msg - !foo get_message
On the other hand mychann_ops.tcl is bound to pub like this:

Code: Select all

bind pub - !foo get_message
As I understood things, this should have been enough to keep each script to its own channel and function.

What I find, however, is that the command !foo when issued in #mychann_ops also triggers mychann.tcl in #mychann - which then throws an error message because of the different number of args expected by get_message when bound to msg as opposed to being bound to pub. Both scripts then terminate. I am thinking of workarounds, but I am really puzzled as to why this behaviour occurs at all, when they have different binds.
Last edited by silenus on Mon Feb 07, 2011 4:28 pm, edited 1 time in total.
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

You are sort of answering your own question. There are indeed two different binds, but they are both bound to the same procedure, or to two different procedures called by the same name... this will always cause troubles.

get_message rename one of them and they will not interfere with eachother
Elen sila lúmenn' omentielvo
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

@silenus : post some code where you're stuck.

@Papillon :shock: OMG! Are you the Papillon i know? :D Dude, where you've been all this time? :P :roll:
Once the game is over, the king and the pawn go back in the same box.
w
willyw
Revered One
Posts: 1203
Joined: Thu Jan 15, 2009 12:55 am

Post by willyw »

s
silenus
Voice
Posts: 10
Joined: Sat Jan 05, 2008 12:37 pm

Post by silenus »

Thank-you all for prompt and helpful responses. After papillon replied I had tried changing the names of the procedures attached to binds, but I was still experiencing a problem with a global variable (same name in both scripts), and now I am having a further problem with another variable (also same name in both scripts). I have feeling that the dominoes will continue to fall as fixing one problem reveals another. I know that these scripts work separately, so the problem must be with their interaction, and it seems that I would be better spending my time learning about the namespaces to which willyw draws my attention than fiddling with names of procs and variables. For this reason caesar, I don't think it would help for me to take up your time by posting code here.

Thanks again - I will mark this "solved"
s
silenus
Voice
Posts: 10
Joined: Sat Jan 05, 2008 12:37 pm

Post by silenus »

Just a short note about the outcome. After half an hour learning about namespaces my scripts now work together without any problems. :)
User avatar
Papillon
Owner
Posts: 724
Joined: Fri Feb 15, 2002 8:00 pm
Location: *.no

Post by Papillon »

@silenus: Good that you solved it. It is just to remember that when you name a global variable or procedure, that name is truly global in your bot. You may have a procedure in one script, but call it from another script. Namespaces helps solve this problem if used correctly :)

@caesar: it is me ye, been studying and generally having a real life once more :)
Elen sila lúmenn' omentielvo
s
silenus
Voice
Posts: 10
Joined: Sat Jan 05, 2008 12:37 pm

Post by silenus »

@Papillon Yes. There are no bugs, only lessons. I am a very amateur programmer and had no clear idea of the way in which scripts work within the bot. I saw them as little packages, ring-fenced by the bind which calls them. I know better now.
Post Reply