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 

My first script - need some assistance.

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


Joined: 26 Feb 2006
Posts: 2

PostPosted: Sun Feb 26, 2006 6:53 am    Post subject: My first script - need some assistance. Reply with quote

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:
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:
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.
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sun Feb 26, 2006 10:54 am    Post subject: Reply with quote

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...
Back to top
View user's profile Send private message MSN Messenger
Sir Edward
Voice


Joined: 26 Feb 2006
Posts: 2

PostPosted: Sun Feb 26, 2006 1:03 pm    Post subject: Reply with quote

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:
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:
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"
Back to top
View user's profile Send private message
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