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.

problem with ;

Old posts that have not been replied to for several years.
Locked
G
Guest

Post by Guest »

i'm writing a "talking script"...
the bot adds text, written by user to the array, and saves it with interval.
the problem is when user writes a text containing ` ; `, then bot adds {} to it
and i get {;)} instead of normal smile ;)
i tried to regsub it ( ` ; ` to ` ; ` ), before adding to array, but it doesn't help and even makes the bot not to write that string to file..

what should i do?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Let it add it to the array like this. Use the "join" command when reading the array later.
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

You aren't handling lists and strings properly. You should paste your script here so one of us can tell you where exactly the problem lies.
G
Guest

Post by Guest »

#i thought it should help, now i think not
proc RegSubStr {str} {
regsub -all {;} $str {;} outstr
return $outstr
}
#adding text written by user to the array
lappend DumbBotArray [RegSubStr $str]
#saving it to file (with for ... $n)
puts $txtf " "[lindex $DumbBotArray $n]""
#or
puts $txtf " {[lindex $DumbBotArray $n]}"

suggestions?

<font size=-1>[ This Message was edited by: abn0rmal on 2001-10-13 20:48 ]</font>
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Due to the way some chars work in TCL, they need to be corectly handled. {}[];$ are a few of these chars.

No regsub is required, just the corect useage of a few commands.

When taking input, use the split command. This will make sure that none of the text is interprited as a commands or anything else.

When writting it to file, use the join command, this will make sure it is written corectly.

EG, lets take a string of text from a channel, and put it into a a list (what you refer to as an array, is actualy a list).

Code: Select all

bind pubm - * test:proc
proc test:proc {nick uh hand chan arg} {
  global mylist
  lappend mylist "[split $arg]"
}
yes, this will mean that ; becomes {;}, but that doesn't matter, as it means the script is corectly storing things.

To write to file, we can now use

Code: Select all

proc writefile {} {
  gloabl mylist
  set fp [open "some.file" w]
  foreach a $mylist {
    puts $fp "[join $a]"
  }
}
G
Guest

Post by Guest »

ohhh.. tried to use:
lappend myarray [split $str]

it doesn't help, bot still adds {} to the text :/

dunno why, i did as you told...
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Post the script here.

Yes, as stated in my previous post, the tcl will add the {}, coz it is suposed to, it could be dangerous not to.

{} = good
{} = good

So long as you join the text later, it will work fine.
G
Guest

Post by Guest »

the thing is that bot adds user-text to list and then reads list and says random phrase.
so i need to get rid of these {} before it saves text to file :)
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

OK - here is a better example, with some output.

Here is a basic TCL session, that takes some punishment with some ; in it.
% set h ""
% lappend h "heya peeps ;)"
{heya peeps ;)}
% lappend h ";)"
{heya peeps ;)} {;)}
% lappend h test
{heya peeps ;)} {;)} test
% lappend h test again
{heya peeps ;)} {;)} test test again
% lappend h {and some more ;)}
{heya peeps ;)} {;)} test test again {and some more ;)}
lappend h {j {;)}}
{heya peeps ;)} {;)} tes test again {and some more ;)} {j {;)}}
OK!

Now, to make make it spit each item in the list out
% foreach a $h { puts stdout $a }
heya peeps ;)
;)
test
test
again
and some more ;)
j {;)}
So lets do it the proper way
% foreach a $h { puts stdout [join $a] }
heya peeps ;)
;)
test
test
again
and some more ;)
j ;)
NOTE: the use of "join" in the last outout, it made sure the {;)} became ;)

<font size=-1>[ This Message was edited by: ppslim on 2001-10-13 21:44 ]</font>
G
Guest

Post by Guest »

no, not so easy, i'm idiot:)))
once again:

proc pub_blabla {nick uhost hand chan strrr} {
set str [split [lrange $strrr 0 end]]
lappend botarray $str
...
proc save_blabla {} {
set fff [open "some_file" w]
for {set n 0} {$n < [llength $botarray]} {incr n} {
if { [lsearch $botarray [lindex $botarray $n]] >= $n } {
puts $fff " "[lindex $botarray $n]""
}

please, show me in my code, where should i use JOIN
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Taking your example and changing it around the the right format yeilds.

Code: Select all

proc pub_blabla {nick uhost hand chan strrr} {
  set str [split $strrr]
  lappend botarray $str

...

proc save_blabla {} {
  set fff [open "some_file" w]
  foreach n $botarray {
    puts $fff " "[join $n]""
  }
There was some un-needed code in there, so removed it.
if { [lsearch $botarray [lindex $botarray $n]] >= $n } {
this is the equvilant of "Stab myself in heart to see if there is a knife in my heart.
G
Guest

Post by Guest »

damn it... after that all bot still says a text with {}
i'll go to sleep now and try to do something tomorrow...

{;)}
Locked