| View previous topic :: View next topic |
| Author |
Message |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Mon Jul 28, 2014 8:40 pm Post subject: Can I use the same variable name for different scripts? |
|
|
I am running all scripts on one eggdrop bot. Is it okay for me to use the same variable name if they are in different scripts? For instance, if I have this line in one script:
| Code: | | set txt [string tolower $txt] |
Can I use the same line of code in another script? Or do I have to change to something else? |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Mon Jul 28, 2014 9:31 pm Post subject: |
|
|
An Eggdrop bot can have only One Global Variable named txt
Usually txt is used in a proc, and that would be a local variable.
In most cases, local variables do not interfere with global variables. _________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
|
| Back to top |
|
 |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Tue Jul 29, 2014 10:29 am Post subject: |
|
|
The article says to use | Code: | | bind pub - "hi" MyScript::respond | in their example. What is the difference between using this and | Code: | | bind pub - "hi" ::MyScript::respond | ? |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Tue Jul 29, 2014 10:52 am Post subject: |
|
|
My guess is that the difference is that in the second the respond proc is inside the MyScript namespace. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Tue Jul 29, 2014 11:09 am Post subject: |
|
|
| caesar wrote: | | My guess is that the difference is that in the second the respond proc is inside the MyScript namespace. |
Both of them are inside the MyScript namespace (I'm looking at another script that uses the double colons before the MyScript bind). What's interesting is, this script I'm looking at uses global. Here is the script:
| Code: | namespace eval magic8ball {
variable 8ballCatch "!8ball"
proc 8ball {nick host handle channel arg} {
global 8ballCatch
set cmd [string tolower [lindex $arg 0]]
if {[file exists /eggdrop/scripts/8ball.txt]} {
set list [open /eggdrop/scripts/8ball.txt r]
set reply ""
while {![eof $list]} {
set tmp [gets $list]
set reply [lappend test [string trim $tmp]]
}
close $list
}
set number [rand [expr [llength $reply] + 1]]
puthelp "PRIVMSG $channel :8-ball\: [lindex $reply $number]"
}
bind pub - $8ballCatch ::magic8ball::8ball
}
|
|
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Thu Jul 31, 2014 6:54 am Post subject: |
|
|
I think that the utility of the lead :: is essentialy when you use the import/export.
And it might be a little bit faster for the tcl to use the full path (::namespace::procedure) than looking in the namespace for the existence of a sub-namespace and then looking in global. _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
|