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 Problem

Old posts that have not been replied to for several years.
Locked
J
Jas0n

Tcl Problem

Post by Jas0n »

I have been setting vars like this...

Code: Select all

set country(south africa) "Code: \002ZA\002 Country: \002South Africa\002"
Then I find out that eggdrop dont like that.

Is there anyway around this with keeping the space?

Thanks
Jason
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Re: Tcl Problem

Post by ppslim »

Jas0n wrote:

Code: Select all

set country(south africa) "Code: \002ZA\002 Country: \002South Africa\002"
Try escaping the space, like you have the control codes. EG

Code: Select all

set country(south\ africa) "Code: \002ZA\002 Country: \002South Africa\002"
Another method method includes

Code: Select all

set temp "south africa"
set country($temp) "Code: \002ZA\002 Country: \002South Africa\002"
J
Jas0n

Post by Jas0n »

I tried what you said an adding the '\' dont work, because it accepts it has 'south\ africa' not just 'south africa' :-?

Anymore ideas?
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

spaces in variables == bad. a space is a core delimiter - using them in varible names will lead to problems later on. this is a core programming rule, which has been in effect ever since the concept of a named variable (or constant) was born. substitute your spaces for underscores (_)
J
Jas0n

Post by Jas0n »

hmmmz.

Well this is wot im trying to do...

Code: Select all

if {$misc1 == "country"} {
    set chr [string tolower $misc2]
    if {![info exists country($chr)]} {
    putserv "NOTICE $nick :Error: \002Country does not exist\002"
    return 0
    }
    putserv "PRIVMSG $chan :$country($chr)"
}

Example of how the vars are set...

Code: Select all

set country(south africa) "Code: \002ZA\002 Country: \002South Africa\002"

Code: Select all

set country(za) "Country: \002South Africa\002 Code: \002ZA\002"
So any ideas how i can do it using the underscores then?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

the setting should be

Code: Select all

set country(south_africa) "Code: \002ZA\002 Country: \002South Africa\002"
In your script, as well as performing a [string] tolower command, your should run it through a de-spacer if you like.

Code: Select all

proc de_spacer {str} {
  regsub -all -- $str { } {_} str
  return $str
}
Once this is in the script, you can pass the country names through it, to convert them to array identifiers.
J
Jas0n

Post by Jas0n »

ok then so it should be.....

Code: Select all

if {$misc1 == "country"} {
    set chr [string tolower $misc2]
    set checkcountry [de_spacer $chr]
    if {![info exists country($checkcountry)]} {
    putserv "NOTICE $nick :Error: \002Country does not exist\002"
    return 0
    }
    putserv "PRIVMSG $chan :$country($checkcountry)"
}

Code: Select all

proc de_spacer {str} { 
  regsub -all -- $str { } {_} str 
  return $str 
} 
Think thats right, but it dont work, keeps saying country does not exist...
:-?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

I have got the syntax of the regsub command mixed up.

It should actualy be

regsub ?switches? exp string subSpec varName

I got the exp and string the wrong way round

it should be

Code: Select all

proc de_spacer {str} {
  regsub -all -- { } $str {_} str
  return $str
}
J
Jas0n

Post by Jas0n »

ok then fixed it but now getting...

[16:17] Tcl error [pub:Cmds]: can't read "country(south)": no such element in array

Sorry to be such a pain!!!!! :-?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Then the variable being passed only has the word south in it.

Seeing the rest of the script would help
J
Jas0n

Post by Jas0n »

Code: Select all

proc pub:Cmds {nick uhost handle chan text} {
    set misc1    "[lindex $text 0]"
    set misc2    "[lindex $text 1]"
if {$misc1 == "country"} {
    set chr [string tolower $misc2]
    regsub -all -- { } $chr {_} chr 
    if {![info exists $country($chr)]} {
    putserv "NOTICE $nick :Error: \002Country does not exist\002"
    return 0
    }
    putserv "PRIVMSG $chan :$country($chr)"
}
}
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Code: Select all

proc pub:Cmds {nick uhost handle chan text} {
  set misc1 [lindex [split $text] 0]
  set misc2 [lrange [split $text] 1 end]
  if {$misc1 == "country"} {
    set chr [string tolower $misc2]
    regsub -all -- { } $chr {_} chr 
    if {![info exists $country($chr)]} {
      putserv "NOTICE $nick :Error: \002Country does not exist\002"
      return 0
    }
    putserv "PRIVMSG $chan :$country($chr)"
  }
}
Locked