egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with my old script Trivia 2000 please
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Ian-Highlander
Op


Joined: 24 Sep 2001
Posts: 165
Location: Ely, Cambridgeshire

PostPosted: Fri Jul 29, 2005 6:25 am    Post subject: Help with my old script Trivia 2000 please Reply with quote

Ok, so four years ago I decided I'd had enough of eggdrop and IRC in general and "retired" from script writing and the world of bots, mainly because of becoming a father and other commitments.

However recently my interest has been sparked again for various reasons, I've set up my old test IRC server again, fired up a couple of bots and been playing with some of my old scripts. Unfortunately to say my TCL is rusty would be a major understatement, I'm trying to fix a couple of niggly little bugs on my old script "Trivia 2000" before moving on to develop the addons that I started years ago and never finished. I've been having to re-aquaint myself with all the code I wrote back then and try and remember what does what and why I wrote it that way. Basically I'm looking for help on a couple of minor issues preparing for a new release if I can get my rear end in gear (primarily because a room I'm in these days is using it and wants some enhancements).

So the bugs and relevant code I could do with a prod in the right direction for are:

The answer file is structured as one question per line with the answer then a colon then the question like so:

answer1:this is question1
answer2:this is question2

etc etc

One of the limitations of Trivia 2000 has always been that it only accepts one word answers in the question files which I never got round to fixing when I knew enough about TCL and dont stand a chance fixing now until I've taught myself it all again. I'm fairly sure one of you guys could fix it in a flash so the code that gets the answer is as below.
Code:
set ques_pair [lindex $quest $questionno]
set puzzle [lindex [split $ques_pair :] 1]
set ques_split [split $ques_pair :]
set answer [lreplace $ques_split 1 1]

The top line is part of the random question code I wrote which just chooses which number question to ask, the rest splits the text into question and answer but for some reason I cant get it to understand multiple word answers. Any help guys?

As well as this, I have a little issue where if one of the answers is a number it takes the first digit as a colour code and then presents the answer in that colour minus the first digit, so 1963 would show up as 963 but in green, again, a minor bug I never dealt with at the time and simply dont have th coding knowledge to deal with now. I imagine this will simply be an edit of the last line of the above code changing the way it reads in the answer code and presents it to the proc as a variable but need some help please guys.

Once I've worked out all the code I started writing years ago for the new version I may actually get round to finishing it and releasing it........IF I can get TCL back into my brain again. Rolling Eyes

Thanks guys Very Happy
_________________
"Insanity Takes Its Toll, Please Have Exact Change"
Back to top
View user's profile Send private message Send e-mail
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Jul 29, 2005 10:07 am    Post subject: Reply with quote

Suppose the format is like this:
Code:
set format "answer1:answer2:answer3:question"

you catch the question like this:
Code:
set question [lindex [split $format :] end]

and catch the answers in a list this way:
Code:
set answers [lrange [split $format :] 0 end-1]

now to match the answer to these answers you can use a foreach loop (I assume you still know how to do this).

As for the color issue, instead of using \0034 for red, use \00304 (notice the 0). This way you won't have a problem with number answers since the color code takes two numbers only. (same goes when you use \00300,00)
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Ian-Highlander
Op


Joined: 24 Sep 2001
Posts: 165
Location: Ely, Cambridgeshire

PostPosted: Sat Jul 30, 2005 9:55 am    Post subject: Reply with quote

Many thanks, those where exactly the sort of pointers I was looking for and a couple of niggly little bugs are now fixed.

I'm hoping to release an interim update to Trivia 2000 soon with a bit of luck Very Happy with a major update to come later this year if I get time.
_________________
"Insanity Takes Its Toll, Please Have Exact Change"
Back to top
View user's profile Send private message Send e-mail
Ian-Highlander
Op


Joined: 24 Sep 2001
Posts: 165
Location: Ely, Cambridgeshire

PostPosted: Tue Aug 02, 2005 6:25 pm    Post subject: Reply with quote

Ok I think I need some more help with this please.

I think my initial question was misunderstood and in my haste to fix the other bits I didnt pick up on it until I actually sat down and started trying to get this damn thing to work lol. I'm not trying to get questions with multiple answers I'm trying to make questions where the answer is more than one word. Probably should have been more clear in my original post sorry.

So currently the quiz file takes the format of:

answer1:this is question number one
answer2:this is question number two

What I want to achieve is something like:

this is answer 1:this is question number one
this is answer 2:this is quesiton number two

I hope I've explained myself a little better.

I've got the answer into a variable with no major issues and have proved that by outputting it to the channel to debug it but I can not for the life of me get the bot to recognise when a multiple word answer is said in the channel. I tried parsing the bind to another proc, lowercasing it, using stripcodes and comparing it to the answer but it just will not under any circumstances work for some strange reason, please show me where the hell I'm going wrong, its driving me nuts now lol

I started with the code in my previous posts and changed it to the following
Code:
        set ques_pair [lindex $quest $questionno]
        set puzzle [lindex [split $ques_pair :] 1]
        set answer [lindex [split $ques_pair :] 0]

        putserv "PRIVMSG $chan :DEBUG - $puzzle - $answer"

#       set ques_split [split $ques_pair :]
#       set answer [lreplace $ques_split 1 1]

        bind pub -|- $answer winner
        putserv "PRIVMSG $chan :Question.......\00304$puzzle"
        incr questionno
        utimer 45 no_answer


The bot in the channel behaves like this:
Code:
<Ian-Highlander> !start
<Mcleod> DEBUG - this is question two - two
<Mcleod> Question.......04this is question two
<Ian-Highlander> two
<Mcleod> Woohoo Ian-Highlander!! You got it right.....04two
<Mcleod> Ian-Highlander you've won 20 times today and 62 times overall, congratulations!!

<Mcleod> DEBUG - this is question five - number five
<Mcleod> Question.......04this is question five
<Ian-Highlander> number five
<Mcleod> No body got it right!!.....04Try Again!!


As you can see from the debug lines it is definitely picking the multiple word answers out from the question file as well as the single word answers with no problems but wont recognise them when said as an answer. So I thought ok the bind isnt picking it up, lets bind everything said in the channel to a new proc which compares the answer variable to a stripped and lowercased version of the text entered by the user and passes it back to the winner proc if it matches. Much more process intensive than I'd like it to be but I just wanted to get the damn thing working. I've now spent hours changing my code back and forth and am just tearing my hair out and still getting absolutely no where, any help would be massively appreciated.
_________________
"Insanity Takes Its Toll, Please Have Exact Change"
Back to top
View user's profile Send private message Send e-mail
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Aug 02, 2005 7:52 pm    Post subject: Reply with quote

if $ques_pair returns <answer>:<question> then [lindex $ques_pair 0] should return the answer even if it has spaces, try to debug that.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Ian-Highlander
Op


Joined: 24 Sep 2001
Posts: 165
Location: Ely, Cambridgeshire

PostPosted: Wed Aug 03, 2005 4:00 am    Post subject: Reply with quote

Sir_Fz wrote:
if $ques_pair returns <answer>:<question> then [lindex $ques_pair 0] should return the answer even if it has spaces, try to debug that.


[lindex $ques_pair 0] only returns the first word in the answer and doesnt catch anything after the first space, unless I'm doing something very very stupid (most likely), my TCL is pretty rusty to put it mildly. Very Happy
_________________
"Insanity Takes Its Toll, Please Have Exact Change"
Back to top
View user's profile Send private message Send e-mail
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Aug 03, 2005 6:23 am    Post subject: Reply with quote

It's probably a problem with your list, otherwise that shouldn't happen (unless you have : instead of a space).
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Ian-Highlander
Op


Joined: 24 Sep 2001
Posts: 165
Location: Ely, Cambridgeshire

PostPosted: Wed Aug 03, 2005 8:15 am    Post subject: Reply with quote

Ok now I'm really really confused.

$ques_pair as a variable returns the whole answer and question. However [lindex $ques_pair 0] using the code above returns totally different things for each one.

ie

If $ques_pair is "one:this is question one"
[lindex $ques_pair 0] returns "one:this"

but

If $ques_pair is "number six:this is question six"
then [lindex $ques_pair 0] returns "number"

Neither of which are right, both stopping at the first space in the line.

Please help this is driving me insane now, I can get it to return the correct sequence of words for the answer using

set answer [lindex [split $ques_pair :] 0]

but I then cant get it to respond to the answer in the channel at all, I though of setting the first word of the answer variable to a command and passing that to a proc which would compare the rest of what was written with the rest of the answer but this seems an overly complicated and process intensive way of doing it and I'm also having no luck getting that working either. There has to be a way, please help Embarassed
_________________
"Insanity Takes Its Toll, Please Have Exact Change"
Back to top
View user's profile Send private message Send e-mail
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Wed Aug 03, 2005 9:51 am    Post subject: Reply with quote

Code:
set data "the answer:is this a question?"

bind pubm - * match:ans

proc match:ans {nick uhost hand chan arg} {
 set myans [lindex [split $::data :] 0]
 if {[string equal -nocase $myans $arg]} {
  puthelp "PRIVMSG $chan :Correct answer!"
 }
}

I don't see how you can't output or match this answer?
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Ian-Highlander
Op


Joined: 24 Sep 2001
Posts: 165
Location: Ely, Cambridgeshire

PostPosted: Wed Aug 03, 2005 2:38 pm    Post subject: Reply with quote

Thankyou, thankyou, thankyou, that pointed me in EXACTLY the right direction and I've finally got it working. Thankyou so much for your patience and help it's hugely appreciated.

This is a snippet of the code I eventually got working using your help.

Code:
   set ques_pair [lindex $quest $questionno]
   set puzzle [lindex [split $ques_pair :] 1]
   set answer [lindex [split $::ques_pair :] 0]

        putserv "PRIVMSG $chan :DEBUG - $ques_pair"
        putserv "PRIVMSG $chan :DEBUG - $answer"

   bind pubm -|- * answercheck
   putserv "PRIVMSG $chan :Question.......\00304$puzzle"
   incr questionno
   utimer 45 no_answer

   setuser $player XTRA wcount.$chan $questionno
   
 }
}

proc answercheck {nick uhost handle channel arg} {
global answer
 if {[string equal -nocase $answer $arg]} {
   winner $nick $uhost $handle $channel
 }
return
}

proc winner {nick uhost handle channel args} {
   global answer chan gameplaying scores winnersay gamechan
if {[string tolower $channel] != [string tolower $gamechan]} {
putserv "PRIVMSG $channel :Sorry $nick, \002\Trivia 2000\002 is not running in $channel, try going to $gamechan, its playing there :o)"
return
}
set chan $gamechan
   putserv "PRIVMSG $chan :Woohoo $nick!! You got it right.....\00304$answer"
   kill_timers
   unbind pubm -|- * answercheck


Thanks again Very Happy
_________________
"Insanity Takes Its Toll, Please Have Exact Change"
Back to top
View user's profile Send private message Send e-mail
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu Aug 04, 2005 11:38 am    Post subject: Reply with quote

You're welcome Smile welcome back to TCL btw Razz
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
Ian-Highlander
Op


Joined: 24 Sep 2001
Posts: 165
Location: Ely, Cambridgeshire

PostPosted: Thu Aug 04, 2005 12:13 pm    Post subject: Reply with quote

Sir_Fz wrote:
You're welcome Smile welcome back to TCL btw Razz


Heh, thanks, it's coming back to me slowly Embarassed Wink
_________________
"Insanity Takes Its Toll, Please Have Exact Change"
Back to top
View user's profile Send private message Send e-mail
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Aug 04, 2005 1:49 pm    Post subject: Reply with quote

*off topic* have you had a brain wash durring this time? Mr. Green
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
Ian-Highlander
Op


Joined: 24 Sep 2001
Posts: 165
Location: Ely, Cambridgeshire

PostPosted: Thu Aug 04, 2005 2:17 pm    Post subject: Reply with quote

Heh, no, just two kids and a new job that takes a large amount of my time hence the now needing a break from the world and picking tcl back up again Wink Laughing
_________________
"Insanity Takes Its Toll, Please Have Exact Change"
Back to top
View user's profile Send private message Send e-mail
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Fri Aug 05, 2005 2:51 pm    Post subject: Reply with quote

heh, congrats then Smile and welcome back Very Happy
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber