| View previous topic :: View next topic |
| Author |
Message |
silenus Voice
Joined: 05 Jan 2008 Posts: 10
|
Posted: Mon Feb 07, 2011 1:19 pm Post subject: Binds to msg and pub allow scripts to interact - SOLVED |
|
|
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: | | bind msg - !foo get_message | On the other hand mychann_ops.tcl is bound to pub like this: | Code: | | 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 |
|
| Back to top |
|
 |
Papillon Owner

Joined: 15 Feb 2002 Posts: 724 Location: *.no
|
Posted: Mon Feb 07, 2011 1:37 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Feb 07, 2011 3:52 pm Post subject: |
|
|
@silenus : post some code where you're stuck.
@Papillon OMG! Are you the Papillon i know? Dude, where you've been all this time?  _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
|
| Back to top |
|
 |
silenus Voice
Joined: 05 Jan 2008 Posts: 10
|
Posted: Mon Feb 07, 2011 4:27 pm Post subject: |
|
|
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" |
|
| Back to top |
|
 |
silenus Voice
Joined: 05 Jan 2008 Posts: 10
|
Posted: Mon Feb 07, 2011 6:14 pm Post subject: |
|
|
Just a short note about the outcome. After half an hour learning about namespaces my scripts now work together without any problems.  |
|
| Back to top |
|
 |
Papillon Owner

Joined: 15 Feb 2002 Posts: 724 Location: *.no
|
Posted: Tue Feb 08, 2011 12:19 pm Post subject: |
|
|
@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 |
|
| Back to top |
|
 |
silenus Voice
Joined: 05 Jan 2008 Posts: 10
|
Posted: Tue Feb 08, 2011 1:34 pm Post subject: |
|
|
| @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. |
|
| Back to top |
|
 |
|