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.

Help with my old script Trivia 2000 please

Help for those learning Tcl or writing their own scripts.
I
Ian-Highlander
Op
Posts: 165
Joined: Mon Sep 24, 2001 8:00 pm
Location: Ely, Cambridgeshire

Help with my old script Trivia 2000 please

Post by Ian-Highlander »

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: Select all

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. :roll:

Thanks guys :D
"Insanity Takes Its Toll, Please Have Exact Change"
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Suppose the format is like this:

Code: Select all

set format "answer1:answer2:answer3:question"
you catch the question like this:

Code: Select all

set question [lindex [split $format :] end]
and catch the answers in a list this way:

Code: Select all

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)
I
Ian-Highlander
Op
Posts: 165
Joined: Mon Sep 24, 2001 8:00 pm
Location: Ely, Cambridgeshire

Post by Ian-Highlander »

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 :D with a major update to come later this year if I get time.
"Insanity Takes Its Toll, Please Have Exact Change"
I
Ian-Highlander
Op
Posts: 165
Joined: Mon Sep 24, 2001 8:00 pm
Location: Ely, Cambridgeshire

Post by Ian-Highlander »

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: Select all

        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: Select all

<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"
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

if $ques_pair returns <answer>:<question> then [lindex $ques_pair 0] should return the answer even if it has spaces, try to debug that.
I
Ian-Highlander
Op
Posts: 165
Joined: Mon Sep 24, 2001 8:00 pm
Location: Ely, Cambridgeshire

Post by Ian-Highlander »

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. :D
"Insanity Takes Its Toll, Please Have Exact Change"
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

It's probably a problem with your list, otherwise that shouldn't happen (unless you have : instead of a space).
I
Ian-Highlander
Op
Posts: 165
Joined: Mon Sep 24, 2001 8:00 pm
Location: Ely, Cambridgeshire

Post by Ian-Highlander »

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 :oops:
"Insanity Takes Its Toll, Please Have Exact Change"
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

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?
I
Ian-Highlander
Op
Posts: 165
Joined: Mon Sep 24, 2001 8:00 pm
Location: Ely, Cambridgeshire

Post by Ian-Highlander »

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: Select all

	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 :D
"Insanity Takes Its Toll, Please Have Exact Change"
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You're welcome :) welcome back to TCL btw :P
I
Ian-Highlander
Op
Posts: 165
Joined: Mon Sep 24, 2001 8:00 pm
Location: Ely, Cambridgeshire

Post by Ian-Highlander »

Sir_Fz wrote:You're welcome :) welcome back to TCL btw :P
Heh, thanks, it's coming back to me slowly :oops: :wink:
"Insanity Takes Its Toll, Please Have Exact Change"
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

*off topic* have you had a brain wash durring this time? :mrgreen:
Once the game is over, the king and the pawn go back in the same box.
I
Ian-Highlander
Op
Posts: 165
Joined: Mon Sep 24, 2001 8:00 pm
Location: Ely, Cambridgeshire

Post by Ian-Highlander »

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: :lol:
"Insanity Takes Its Toll, Please Have Exact Change"
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

heh, congrats then :) and welcome back :D
Once the game is over, the king and the pawn go back in the same box.
Post Reply