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.

My first script - need some assistance.

Help for those learning Tcl or writing their own scripts.
Post Reply
S
Sir Edward
Voice
Posts: 2
Joined: Sun Feb 26, 2006 6:38 am

My first script - need some assistance.

Post by Sir Edward »

Hello. I have just recently learned Tcl and started modifying scripts and decided to build my own. What this does is check if the BNCs are in my logging channel and is suppose to post it to an HTML document.. but nothing seems to be working. Any help would be greatly appreciated.

This is the main script, bncstat.tcl:

Code: Select all

source ./scripts/database.tcl
source ./scripts/htmlstat.tcl

timer 5 updatemagus
timer 5 updatemaes
putlog "Trying timers"
timer 5 updategendo
timer 5 updatecid
timer 5 "set lol [expr rand()]"
timer 6 updatepage
set statchan \#vservices
putlog $statchan


proc updatemagus {} {
	global botnick $statchan magus lol
	if {[onchan Magus $statchan]} {
		set magus Yes
	} else {
		set magus No
	}
}
proc updatemaes {} {
	global botnick $statchan gendo
	if {[onchan Maes_Hughes $statchan]} {
		set maes Yes
	} else {
		set maes No
	}
}
proc updategendo {} {
	global botnick $statchan gendo
	if {[onchan Gendo_Ikari $statchan]} {
		set gendo Yes
	} else {
		set gendo No
	}
}
proc updatecid {} {
	global botnick $statchan cid
	if {[onchan Cid_Highwind $statchan]} {
		set cid Yes
	} else {
		set cid No
	}
}

proc updatepage {} {
	set datafile [open "database.tcl" w]
	puts $datafile "set magusstat $magus"
	puts $datafile "set maesstat $maes"
	puts $datafile "set gendostat $gendo"
	puts $datafile "set cidstat $cid"
	puts $datafile "set lolstat $lol"
	global magusstat maesstat gendostat cidstat lolstat
	html_stat
}

putlog "loaded"
And this is the htmlstat.tcl used to edit the html file.

Code: Select all

proc html_stat {} {
	global cid magus maes gendo cidstat magusstat maesstat gendostat lol lolstat statchan
	puts index.html "<HTML><HEAD><TITlE>BNC Stat</TITLE></HEAD><BODY>"
	puts index.html "Magus: $magusstat"
	puts index.html "Maes_Hughes: $maesstat"
	puts index.html "Gendo_Ikari: $gendostat"
	puts index.html "Cid_Highwind: $cidstat"
	puts index.html "LOL: $lolstat</BODY></HTML>"
}
Thanks.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

proc html_stat needs rework. 1 major problems I can use on first sight:
- you cannot use file names with puts, but you must use file handles (like in proc updatepage)

then I see a general problem:
- you cannot use $var from procs which are higher/lower levels. you must explicitly make them global, catch them via upvar or give them as parameters.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
S
Sir Edward
Voice
Posts: 2
Joined: Sun Feb 26, 2006 6:38 am

Post by Sir Edward »

Thank you for the reply. I did my best attempt to fix the variable problem here, albeit I do not know if it's completely correct (It doesn't function correctly, so it's easy to assume that):

Code: Select all

proc html_stat {} {
   set htmlfile [open "index.html" w] 
   upvar magus magusstat maes maesstat gendo gendostat cid cidstat lol lolstat
   puts $htmlfile "<HTML><HEAD><TITlE>BNC Stat</TITLE></HEAD><BODY>"
   puts $htmlfile "Magus: $magusstat"
   puts $htmlfile "Maes_Hughes: $maesstat"
   puts $htmlfile "Gendo_Ikari: $gendostat"
   puts $htmlfile "Cid_Highwind: $cidstat"
   puts $htmlfile "LOL: $lolstat </BODY></HTML>"
} 

Code: Select all

source ./scripts/database.tcl
source ./scripts/htmlstat.tcl

timer 5 updatemagus
timer 5 updatemaes
putlog "Trying timers"
timer 5 updategendo
timer 5 updatecid
timer 5 "set lol [expr rand()]"
timer 6 updatepage
set statchan \#vservices
putlog $statchan


proc updatemagus {} {
   global botnick $statchan magus lol
   if {[onchan Magus $statchan]} {
      set magus Yes
   } else {
      set magus No
   }
   upvar magus magustat
}
proc updatemaes {} {
   global botnick $statchan gendo
   if {[onchan Maes_Hughes $statchan]} {
      set maes Yes
   } else {
      set maes No
   }
   upvar maes maesstat
}
proc updategendo {} {
   global botnick $statchan gendo
   if {[onchan Gendo_Ikari $statchan]} {
      set gendo Yes
   } else {
      set gendo No
   }
   upvar gendo gendostat
}
proc updatecid {} {
   global botnick $statchan cid
   if {[onchan Cid_Highwind $statchan]} {
      set cid Yes
   } else {
      set cid No
   }
   upvar cid cidstat
}

proc updatepage {} {
   set datafile [open "database.tcl" w]
   puts $datafile "set magusstat $magus"
   puts $datafile "set maesstat $maes"
   puts $datafile "set gendostat $gendo"
   puts $datafile "set cidstat $cid"
   puts $datafile "set lolstat $lol"
   upvar magus magusstat maes maesstat gendo gendostat cid cidstat lol lolstat
   html_stat
}

putlog "loaded"
Post Reply