egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can I use the same variable name for different scripts?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
daigo
Voice


Joined: 27 Jun 2014
Posts: 37

PostPosted: Mon Jul 28, 2014 8:40 pm    Post subject: Can I use the same variable name for different scripts? Reply with quote

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
Code:
txt
to something else?
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Mon Jul 28, 2014 9:31 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Tue Jul 29, 2014 8:24 am    Post subject: Reply with quote

You might like to read:

http://forum.egghelp.org/viewtopic.php?t=12900
Back to top
View user's profile Send private message
daigo
Voice


Joined: 27 Jun 2014
Posts: 37

PostPosted: Tue Jul 29, 2014 10:29 am    Post subject: Reply with quote

willyw wrote:
You might like to read:

http://forum.egghelp.org/viewtopic.php?t=12900

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
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue Jul 29, 2014 10:52 am    Post subject: Reply with quote

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
View user's profile Send private message
daigo
Voice


Joined: 27 Jun 2014
Posts: 37

PostPosted: Tue Jul 29, 2014 11:09 am    Post subject: Reply with quote

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
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Thu Jul 31, 2014 6:54 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber