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.

TCL really sucks..

Old posts that have not been replied to for several years.
Locked
B
BaGGy

Post by BaGGy »

TCL really sucks because I cant find anyone who can help me program for it, I am having problems with one thing and I need help. I have searched DALnet, Undernet, and IRCnet for help and no one was a TCL programmer or they are all bots or even away.

I really could use some help.

BTW add PHP coding support hehe i cant stand tcl, i am sorry but i cant!
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

maybe if you said what your one thing was we'd be able to help
B
BaGGy

Post by BaGGy »

B
BaGGy

Post by BaGGy »

Ok what i am trying to do is make a script that will search a flatfile and give output.

What: I am making a script that will make it easier for users to check the release dates of certain xbox games just by typing the trigger and gamename. I also want master users to be able to add/remove games to the list.

How: How it will work is like this:

Code: Select all

(">" == user output && "<" == bot input && ">>" == bot output)

> .released DoA3
<< Search for DoA3....
<< DoA3 found in game number 43 "43#Dead or Alive 3#Out#2#Action#No#Techmo#Team Ninja#DoA3#DoA 3#doa"
>> (43) [b]Game Name:[/b] Dead or Alive 3  [b]Release Date:[/b] Out  [b]Genre:[/b] Action  [b]Multiplayer Support:[/b] No [b]Publisher:[/b] Techmo  [b]Developer:[/b] Team Ninja 
<font size=-1>[ This Message was edited by: BaGGy on 2002-01-20 23:44 ]</font>

<font size=-1>[ This Message was edited by: BaGGy on 2002-01-20 23:46 ]</font>
B
BaGGy

Post by BaGGy »

-=-=-=-=-=-=-=-=-=-=-=-=-=-
Here is the source so far:
-=-=-=-=-=-=-=-=-=-=-=-=-=-

Code: Select all

# Location of the file to store data in.
set released(datafile) "xgame.dat"
#############################################################################
# Set this to how many records you want it to keep track of.
set released(max) 10000
#############################################################################
# Access flag needed to add an entry
set released(entryaccess) "m"
#############################################################################
# Access flag needed to remove and entry
set released(killaccess) "m"
#############################################################################
set released(noentries) {Currently, no entries have been added.}
#############################################################################
set released(header) {
 {Test Header}
                     }
set released(footer) {
 {Test Footer}
                      }
set released(ver) "v1.0.0"
#############################################################################
set cmdchar_ "."

proc cmdchar { } {
 global cmdchar_
 return $cmdchar_
}

for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {set released($rloop) ""}

bind pub - [cmdchar]released pub_released
proc pub_released {nick uhost hand channel rest} {
 global released

 set rnum 0
 #foreach oline {putserv "NOTICE $nick :[set_control $nick $channel $oline]"}
for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {
  if {$released($rloop) != ""} {set r_time [ctime [lindex $released($rloop) 0]]
                                set r_desc [lrange $released($rloop) 0 end]
                                putserv "PRIVMSG $channel : [format "%2s" $rloop]: $r_desc"
                                incr rnum
                               }
                      }
 if {$rnum == 0} {putserv "NOTICE $nick :[set_control $nick $channel $released(noentries)]"}
 #foreach oline {putserv "NOTICE $nick :[set_control $nick $channel $oline]"}
}
<font size=-1>[ This Message was edited by: BaGGy on 2002-01-20 23:44 ]</font>
B
BaGGy

Post by BaGGy »

Code: Select all

bind pub $released(killaccess) [cmdchar]killrelease pub_killrelease
proc pub_killrelease {nick uhost hand channel rest} {
 global released

 if {($rest < 0) || ($rest > $released(max))} {putserv "NOTICE $nick :$rest is an invalid entry. Must be between 1 and $released(max)"
                                               return 0}
 if {$released(1) == ""} {putserv "NOTICE $nick :There are no release notes in the database."
                          return 0}

for {set rloop $rest} {$rloop < $released(max)} {incr rloop} {
  set rloop1 [expr $rloop + 1]
  set released($rloop) $released($rloop1)
                               }
 set released($released(max)) ""
 putserv "NOTICE $nick :#$rest has been deleted."
 save_released
}

bind pub $released(entryaccess) [cmdchar]newrelease pub_newrelease
proc pub_newrelease {nick uhost hand chan rest} {
 global released

 if {$rest == ""} {putserv "NOTICE $nick :Calling Syntax: [cmdchar]newrelease Some text string"
                   return 0}

for {set rloop $released(max)} {$rloop > 1} {incr rloop -1} {
  set rloop1 [expr $rloop - 1]
  set released($rloop) $released($rloop1)
                                                         }
 set released(1) "$rest"
 putserv "NOTICE $nick :Added entry for as $rest"
 save_released
}

proc save_released {} {
global released
 putlog "Saving Released $released(ver) Data"
 set out [open $released(datafile) w]
for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {puts $out $released($rloop)}
 close $out
}

proc load_released {} {
global released
  if {[file exists $released(datafile)]} {
putlog "Loading Released data from $released(datafile)"
                                 set in [open $released(datafile) r]
for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {set released($rloop) [gets $in]}
                                 close $in
                                          }
}
load_released

proc set_control {nick chan outmsg} {
 regsub -all {$nick} $outmsg $nick outmsg
 regsub -all {$chan} $outmsg $chan outmsg
 regsub -all {[1code]
bind pub $released(killaccess) [cmdchar]killrelease pub_killrelease
proc pub_killrelease {nick uhost hand channel rest} {
 global released

 if {($rest < 0) || ($rest > $released(max))} {putserv "NOTICE $nick :$rest is an invalid entry. Must be between 1 and $released(max)"
                                               return 0}
 if {$released(1) == ""} {putserv "NOTICE $nick :There are no release notes in the database."
                          return 0}

for {set rloop $rest} {$rloop < $released(max)} {incr rloop} {
  set rloop1 [expr $rloop + 1]
  set released($rloop) $released($rloop1)
                               }
 set released($released(max)) ""
 putserv "NOTICE $nick :#$rest has been deleted."
 save_released
}

bind pub $released(entryaccess) [cmdchar]newrelease pub_newrelease
proc pub_newrelease {nick uhost hand chan rest} {
 global released

 if {$rest == ""} {putserv "NOTICE $nick :Calling Syntax: [cmdchar]newrelease Some text string"
                   return 0}

for {set rloop $released(max)} {$rloop > 1} {incr rloop -1} {
  set rloop1 [expr $rloop - 1]
  set released($rloop) $released($rloop1)
                                                         }
 set released(1) "$rest"
 putserv "NOTICE $nick :Added entry for as $rest"
 save_released
}

proc save_released {} {
global released
 putlog "Saving Released $released(ver) Data"
 set out [open $released(datafile) w]
for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {puts $out $released($rloop)}
 close $out
}

proc load_released {} {
global released
  if {[file exists $released(datafile)]} {
putlog "Loading Released data from $released(datafile)"
                                 set in [open $released(datafile) r]
for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {set released($rloop) [gets $in]}
                                 close $in
                                          }
}
load_released

proc set_control {nick chan outmsg} {
 regsub -all {$nick} $outmsg $nick outmsg
 regsub -all {$chan} $outmsg $chan outmsg
 regsub -all {01} $outmsg 01 outmsg
 regsub -all {02} $outmsg 02 outmsg
 regsub -all {26} $outmsg 26 outmsg
 return "$outmsg"
}


putlog "XboxGameInfo $released(ver) by `BaGGy` loaded."
return "XboxGameInfo $released(ver) by `BaGGy` loaded."
<font size=-1>[ This Message was edited by: BaGGy on 2002-01-20 23:46 ]</font>
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

First of all, why didn't you post this under "Tcl & Programming Forum" since this is a Tcl programming question?

Your script seems overly complicated. Instead of storing everything in one array, have config data in an array, and the release data in a list. Then you can cycle through the releases using a simple "foreach" statement, and search for releases using "lsearch".

Or, instead of indexing the entries with a number, why don't you use something more descriptive, like the game's name, or an abbreviation for it? Then you won't have to do that loop to shift the higher entries down when you delete.

You shouldn't need loops to read/write your file, either.

To save your release data:
puts $fp [join [array get releases] "n"]

To read your release data:
array set releases [split [read -nonewline $fp] "n"]

(This assumes there is no newline in the release data.. you could use another character like 01 if you want to use newlines. Also, if you make it a list instead of an array, you don't need the "array get" and "array set" parts.)

Also, did you screw up the copy/paste or something? You have a bunch of repeated code.

You seem to have pub_released already, but it just prints out all the releases? Do you want to add a search capability to it? If so, look up "string match" or "regexp" and you'll see what to do.

Also, about your first comment, if you can't find anyone to help you, why don't you go read the Tcl manual yourself? All the commands are explained at http://tcl.activestate.com and http://dev.scriptics.com

Just a general note, you might find Tcl programming easier if you use normal indentation. It's certainly easier to read and debug.

Your code:

Code: Select all

proc load_released {} {
global released
  if {[file exists $released(datafile)]} {
putlog "Loading Released data from $released(datafile)"
                                 set in [open $released(datafile) r]
for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {set released($rloop) [gets $in]}
                                 close $in
                                          }
}
Normal code:

Code: Select all

proc load_released {} {
  global released
  if {[file exists $released(datafile)]} {
    putlog "Loading Released data from $released(datafile)"
    set in [open $released(datafile) r]
    for {set rloop 1} {$rloop < [expr $released(max) + 1]} {incr rloop} {
      set released($rloop) [gets $in]
    }
    close $in
  }
}
See isn't that more sane? Hehe, seriously I don't even understand how you choose where to put your closing braces, they're totally random.
Locked