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.

adding another arg to existing script

Help for those learning Tcl or writing their own scripts.
Post Reply
j
jonathan3061
Voice
Posts: 2
Joined: Tue Apr 10, 2007 1:16 pm

adding another arg to existing script

Post by jonathan3061 »

i currently have this piece of script:

Code: Select all

proc war_addmatch {nick uhost handle channel arg} {
  global war_privchan war_counter war_authsys botnick war_playernumber war_trigger
  set channel [string tolower $channel]
  if {$channel==$war_privchan} {
    if {(![matchattr $handle V])&&($war_authsys==1)} {
      putserv "NOTICE $nick :5You are not authed, use /msg $botnick [string trim $war_trigger]admin <password>"
      return 0
    }
    set check [war_charfilter $arg]
    if {$check!=1} {
      putserv "NOTICE $nick :5Invalid character: \"$check\". Please do not use such character in any field."
      return 0
    }
    if {([lsearch $arg "team(*"]==-1)||([lsearch $arg "date(*"]==-1)||([lsearch $arg "map(*"]==-1)} {
      putserv "NOTICE $nick :5Invalid args, you need to enter at least the team(x), date(hh:mm-dd/mm/yy) and map(x) ( + info(x) or number(x) )"
      return 0
    }
    set startindex [lsearch $arg "date(*"]
    set buf [lrange $arg $startindex end]
    set infos [string range $buf 5 [expr [string first ")" $buf]-1]]
    set errormsg [war_checkdate $infos]
    if {$errormsg!=1} {
      putserv "NOTICE $nick :$errormsg"
      return 0
    }
    set infos [clock scan "[string range $infos 12 13][string range $infos 9 10][string range $infos 6 7] [string range $infos 0 1][string range $infos 3 4]00"]
    set infos [linsert $infos 0 $war_counter]
    set startindex [lsearch $arg "team(*"]
    set buf [lrange $arg $startindex end]
    set team [string range $buf 5 [expr [string first ")" $buf]-1]]
    set startindex [lsearch $arg "map(*"]
    set buf [lrange $arg $startindex end]
    set map [string range $buf 4 [expr [string first ")" $buf]-1]]
    set info "nothing"
    if {[lsearch $arg "info(*"]>-1} {
      set startindex [lsearch $arg "info(*"]
      set buf [lrange $arg $startindex end]
      set info [string range $buf 5 [expr [string first ")" $buf]-1]]
    }
    set number $war_playernumber
    if {[lsearch $arg "number(*"]>-1} {
      set startindex [lsearch $arg "number(*"]
      set buf [lrange $arg $startindex end]
      set number [string range $buf 7 [expr [string first ")" $buf]-1]]
    }
    set infos [linsert $infos end $team "n/a" "n/a" $map "n/a" $info $number]
    war_insertion $infos
    war_savefiles
    set infos [war_getinfos $war_counter 2]
    incr war_counter
    set id [lindex $infos 0]
    set hour [lindex $infos 1]
    set date [lindex $infos 2]
    set team [lindex $infos 3]
    set maps [lindex $infos 6]
    set info [lindex $infos 8]
    set number [lindex $infos 9]
    if {$number==$war_playernumber} {
      putserv "PRIVMSG $channel : 5New war on $date at $hour against $team . Maps: $maps . Infos: $info ( ID $id )"
    } else {
      putserv "PRIVMSG $channel : 5New war on $date at $hour against $team . Maps: $maps . Infos: $info . Player number: $number . ( ID $id )"
    }
    war_automanagement
  }
}
and i'm trying to add in another $arg , I want it to work the same as $info but I can't get it to work :s. I don't know much of TCL scripting... this is what i've tried so far:

Code: Select all

proc war_addmatch {nick uhost handle channel arg} {
  global war_privchan war_counter war_authsys botnick war_playernumber war_trigger
  set channel [string tolower $channel]
  if {$channel==$war_privchan} {
    if {(![matchattr $handle V])&&($war_authsys==1)} {
      putserv "NOTICE $nick :5You are not authed, use /msg $botnick [string trim $war_trigger]admin <password>"
      return 0
    }
    set check [war_charfilter $arg]
    if {$check!=1} {
      putserv "NOTICE $nick :5Invalid character: \"$check\". Please do not use such character in any field."
      return 0
    }
    if {([lsearch $arg "team(*"]==-1)||([lsearch $arg "date(*"]==-1)||([lsearch $arg "map(*"]==-1)} {
      putserv "NOTICE $nick :5Invalid args, you need to enter at least the team(x), date(hh:mm-dd/mm/yy) and map(x) ( + info(x) or number(x) )"
      return 0
    }
    set startindex [lsearch $arg "date(*"]
    set buf [lrange $arg $startindex end]
    set infos [string range $buf 5 [expr [string first ")" $buf]-1]]
    set errormsg [war_checkdate $infos]
    if {$errormsg!=1} {
      putserv "NOTICE $nick :$errormsg"
      return 0
    }
    set infos [clock scan "[string range $infos 12 13][string range $infos 9 10][string range $infos 6 7] [string range $infos 0 1][string range $infos 3 4]00"]
    set infos [linsert $infos 0 $war_counter]
    set startindex [lsearch $arg "team(*"]
    set buf [lrange $arg $startindex end]
    set team [string range $buf 5 [expr [string first ")" $buf]-1]]
    set startindex [lsearch $arg "map(*"]
    set buf [lrange $arg $startindex end]
    set map [string range $buf 4 [expr [string first ")" $buf]-1]]
    set info "nothing"
    if {[lsearch $arg "info(*"]>-1} {
      set startindex [lsearch $arg "info(*"]
      set buf [lrange $arg $startindex end]
      set info [string range $buf 5 [expr [string first ")" $buf]-1]]
    }
    set number $war_playernumber
    if {[lsearch $arg "number(*"]>-1} {
      set startindex [lsearch $arg "number(*"]
      set buf [lrange $arg $startindex end]
      set number [string range $buf 7 [expr [string first ")" $buf]-1]]
    }
    set type "pcw"
    if {[lsearch $arg "type(*"]>-1} {
      set startindex [lsearch $arg "type(*"]
      set buf [lrange $arg $startindex end]
      set type [string range $buf 5 [expr [string first ")" $buf]-1]]
    }

    set infos [linsert $infos end $team "n/a" "n/a" $map "n/a" $info $number $type]
    war_insertion $infos
    war_savefiles
    set infos [war_getinfos $war_counter 2]
    incr war_counter
    set id [lindex $infos 0]
    set hour [lindex $infos 1]
    set date [lindex $infos 2]
    set team [lindex $infos 3]
    set maps [lindex $infos 6]
    set info [lindex $infos 8]
    set number [lindex $infos 9]
    set type [lindex $infos 10]
    if {$number==$war_playernumber} {
      putserv "PRIVMSG $channel : 5New $type on $date at $hour against $team . Maps: $maps . Infos: $info ( ID $id )"
    } else {
      putserv "PRIVMSG $channel : 5New $type on $date at $hour against $team . Maps: $maps . Infos: $info . Player number: $number . ( ID $id )"
    }
    war_automanagement
  }
}
Can anybody please push me in the right direction and explain me what i'm doing wrong? :D
j
jonathan3061
Voice
Posts: 2
Joined: Tue Apr 10, 2007 1:16 pm

Post by jonathan3061 »

anyone :roll: :?:

:D
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Without knowing how "war_getinfos" is written, it would be pretty hard to know how to help you with your request.
NML_375
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

It would also be helpful if you posted a *summary* of what you tried, and what exactly you're trying to test, rather than the entire script, as it's very difficult to see any changes the way you posted. I'm not inclined to save both copies just to 'diff' them to figure out what is different. There's also function calls (such as set check [war_charfilter $arg] ) but you didn't post those functions so it's impossible to tell what is being done..

So, tell us what the content of $args is, and what you're trying to add as a new arg, and what you want as a new test.

In general, you need to use lindex to split $arg into new vars.
Post Reply