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.

Changing 1 string to 3 parts

Old posts that have not been replied to for several years.
Locked
j
jimmyx
Voice
Posts: 11
Joined: Mon Jul 14, 2003 6:51 pm

Changing 1 string to 3 parts

Post by jimmyx »

I was wondering it was possible to change 1 text string (for example: bob is cool) and make it into 3 seperate strings, bob, is, and cool. How would I go about doing this? I've used the search function, but I didn't find anything that could help, well..that I could understand. :oops:

I guess that wasn't really that clear, so what im trying to do is having people message the bot with: !add bob is cool and having it put in the text file I set, but like this:

[word1]
bob

[word2]
is

[word3]
cool

Is it possible? :oops:
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

How about this:

Code: Select all

set word1 [lindex $text 0]
set word2 [lindex $text 1]
set word3 [lindex $text 2]
Once the game is over, the king and the pawn go back in the same box.
j
jimmyx
Voice
Posts: 11
Joined: Mon Jul 14, 2003 6:51 pm

Post by jimmyx »

I'm guessing its either a stupid noob mistake -- or I should start reading up the tcl documentation some more. But here's a snipplet of what I have:

Code: Select all

proc addstrings {nick uhost w1 w2 w3 text} {
        global mainchan file
        putserv "NOTICE $mainchan : $nick ( $uhost ) adding $text to $file"
        set fs [open strings.txt w]
        set w1 [lindex $text  0]
        set w2 [lindex $text  1]
        set w3 [lindex $text  2] 
        puts $fs "1. $w1 2. $w2 3. $w3"
        close $fs
        putserv "NOTICE $mainchan : $text added."
        return 1
}
It won't write anything to strings.txt..

I have addstrings binded to a msg, could that be why its not working? what could i use other than $text?

I've just recently started messing around with tcl..so I don't really understand much. :oops:
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

try adding this : set text [split $text] (I think that the bot must split the text before using [lindex....])
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

jimmyx wrote:I'm guessing its either a stupid noob mistake -- or I should start reading up the tcl documentation some more. But here's a snipplet of what I have:

Code: Select all

proc addstrings {nick uhost w1 w2 w3 text} {
        global mainchan file
        putserv "NOTICE $mainchan : $nick ( $uhost ) adding $text to $file"
        set fs [open strings.txt w]
        set w1 [lindex $text  0]
        set w2 [lindex $text  1]
        set w3 [lindex $text  2] 
        puts $fs "1. $w1 2. $w2 3. $w3"
        close $fs
        putserv "NOTICE $mainchan : $text added."
        return 1
}
It won't write anything to strings.txt..

I have addstrings binded to a msg, could that be why its not working? what could i use other than $text?

I've just recently started messing around with tcl..so I don't really understand much. :oops:
I'm guessing you see an error in the partyline saying something to the effect of: "proc addstrings called with not enough arguments"

Consult doc/tcl-commands.doc for the # of parameters a msg bound proc must have.
j
jimmyx
Voice
Posts: 11
Joined: Mon Jul 14, 2003 6:51 pm

Post by jimmyx »

I got it.

Thanks for your help, guys.
Locked