Communauté Eggdrop

Version complète : Bug bizarre : Namespace, array et socket
Vous consultez actuellement la version basse qualité d’un document. Voir la version complète avec le bon formatage.
Bonjour ici.

Je tente de faire un système qui connectera un pseudo-bot via un socket. Sauf que j'ai un bug vraiment étrange avec la variable de configuration:
tcl
namespace eval sockegg {
 
	set egg(clone1) {
		nick "clone1"
		realname "I am a clone"
		identd "bwaaa"
		serv	"irc.zeolia.net"
		port	6667
		host	"I.am.a.clone"
		idx	0
	}
 
	variable bot
 
	bind dcc - "clone" [namespace current]::come
	proc come { i f a } {
		[namespace current]::connect clone1 $a
	}
 
	proc connect {nick chan} {
		array set ::sockegg::bot $::sockegg::egg($nick)
		putlog "Going to $::sockegg::bot(serv)"
		set mserver $::sockegg::bot(serv)
		set mport $::sockegg::bot(port)
		putlog "Connection to $mserver $mport"
		set ::sockegg::bot(idx) [connect $mserver $mport]
		control $::sockegg::bot(idx) $chan
		putdcc $::sockegg::bot(idx) "USER $::sockegg::bot(nick) 0 0 :$::sockegg::bot(realname)"
		putdcc $::sockegg::bot(idx) "NICK $::sockegg::bot(nick)"
	}
 
	bind dcc - "unclone" [namespace current]::go
	proc go {i f a} {
		array set ::sockegg::bot $::sockegg::egg($nick)
		killdcc $::sockegg::bot(idx)
		set ::sockegg::bot(idx) 0
	}
}



Voici l'erreur:
Citation :.clone #test
[15:46:56] Going to irc.zeolia.net
[15:46:56] Connection to irc.zeolia.net 6667
[15:46:56] Tcl error [::sockegg::come]: can't read "::sockegg::egg(irc.zeolia.net)": no such element in array
.set errorInfo
[15:47:12] tcl: builtin dcc call: *dcc:set CrazyCat 24 errorInfo
[15:47:12] #CrazyCat# set errorInfo
Currently: can't read "::sockegg::egg(irc.zeolia.net)": no such element in array
Currently: while executing
Currently: "array set ::sockegg::bot $::sockegg::egg($nick)"
Currently: (procedure "connect" line 2)
Currently: invoked from within
Currently: "connect $mserver $mport"
Currently: (procedure "::sockegg::connect" line 7)
Currently: invoked from within
Currently: "[namespace current]::connect clone1 $a"
Currently: (procedure "::sockegg::come" line 2)
Currently: invoked from within
Currently: "::sockegg::come $_dcc1 $_dcc2 $_dcc3"
Donc, d'où me sort-il ce ::sockegg::egg(irc.zeolia.net) ?
salut,

pourquoi utilises-tu le chemin complet vers la variable alors que tu es déjà dans le namespace?

tcl
proc connect {nick chan} {
      variable egg
      variable bot
      array set bot $egg($nick)
      putlog "Going to $bot(serv)"
      set mserver $bot(serv)
      set mport $bot(port)
      putlog "Connection to $mserver $mport"
      set bot(idx) [connect $mserver $mport]
      control $bot(idx) $chan
      putdcc $bot(idx) "USER $bot(nick) 0 0 :$bot(realname)"
      putdcc $bot(idx) "NICK $bot(nick)"
   }



ensuite pour l erreur en elle même, c'est normal, tu reprends comme nom de procédure "connect" je penses que ça doit entrer en conflit.
Citation :Currently: (procedure "connect" line 2)
Currently: invoked from within
Currently: "connect $mserver $mport"
tu le renvois en boucle sur la procédure connect de ton namespace avec comme argument "irc.zeolia.net" "6667"
essais comme ça:
tcl
set bot(idx) [::connect $mserver $mport]


pour utiliser la procédure connect classique.
tcl cherche d'abord dans le namespace ou il se trouves
djkenny a écrit :ensuite pour l erreur en elle même, c'est normal, tu reprends comme nom de procédure "connect" je penses que ça doit entrer en conflit.
Citation :Currently: (procedure "connect" line 2)
Currently: invoked from within
Currently: "connect $mserver $mport"
tu le renvois en boucle sur la procédure connect de ton namespace avec comme argument "irc.zeolia.net" "6667"
essais comme ça:
tcl
set bot(idx) [::connect $mserver $mport]


pour utiliser la procédure connect classique.
tcl cherche d'abord dans le namespace ou il se trouves
Ph la buse ! Merci djkenny, je suis vraiment stupide !
stupide non, c'est une faute d'inattention (que j'ai déjà commise surtout avec "connect" et "join")