mIRC Home    About    Download    Register    News    Help

Print Thread
#134200 30/10/05 12:10 AM
Joined: Oct 2005
Posts: 54
B
Babel fish
OP Offline
Babel fish
B
Joined: Oct 2005
Posts: 54
Could someone be able to give/help me make a script to rip apart half a sentence, like a question | answer gather (all on one line)
example.
2+2*4

and would return
%question 2+2
%answer 4
(i think you can use tokens for this but i have no idea how to use those yet)
Thanks grin


Chat NSN
My Server: sleepystickman.ircxpro.com
Joined: Feb 2004
Posts: 206
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Feb 2004
Posts: 206
Quote:
Could someone be able to give/help me make a script to rip apart half a sentence, like a question | answer gather (all on one line)
example.
2+2*4

and would return
%question 2+2
%answer 4
(i think you can use tokens for this but i have no idea how to use those yet)
Thanks grin


/help $gettok
/help tokenize

will be a start - make some small scripts to experiment with - you will find it surprisingly easy! There are also some examples in the help files.

Cheers,

DK


Darwin_Koala

Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
Joined: Oct 2005
Posts: 54
B
Babel fish
OP Offline
Babel fish
B
Joined: Oct 2005
Posts: 54
Thats the problem, the help file didn't help as much as it could =\
Waittttttttttttttttttttt aha, one last question, can you pull out $mid()s with tokens?


Chat NSN
My Server: sleepystickman.ircxpro.com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Probably... it depends what you mean by pulling out $mid()s. An example of how you want that to work would help.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2005
Posts: 54
B
Babel fish
OP Offline
Babel fish
B
Joined: Oct 2005
Posts: 54
I've got a problem now =\
im using the following
Code:
var %y $remove($mid(%x,$wildtok(%x,[ * ],1,32),$len(%x)),[,])
for the answer (yes it seems and looks complicated)
...it returns What is 2+2? 4 instead of 4 from "What is 2+2?[ 4 ]"...
Thanks if you could help ^_^
Full alias
Code:
alias -l get.question {
  var %x $read(questions.txt)
  var %y $remove($mid(%x,$wildtok(%x,[ * ],1,32),$len(%x)),[,])
  var %q $mid(%x,1,$calc($pos(%x,[,1) - 1))
  return %q
  if ($readini(benstriv_vars.ini,MAIN,echoanswer) == 1) { echo 4 %y }
  set %currentquestion %q
}


Chat NSN
My Server: sleepystickman.ircxpro.com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
//set %x What is 2+2? [4]
//echo -a $remove($wildtok(%x,[*],1,32),[,])

A token is a single "word" that is separated by the token character. Because you have a space as the separator (32), you can't use wildtok with the answer having spaces in it. You must also put a space before the [ as shown above and not have the [ touching the ?.

Of course, you could make your trivia script use the same format for questions that most others use...

//set %trivia What is 2+2*4
//echo -a The question is: $gettok(%trivia,1,42) $+ ?
//echo -a The answer is: $gettok(%trivia,2,42)

Just don't include a ? in the question as it will be added automatically. You could make it NOT add the ? automatically, but most scripts add it, so it may be a good idea to stick to a similar method. That way, you can easily accept the questions from other trivia or have users submit trivia using the same format they are used to using with other trivia scripts.

As a note, you can't have a * in the question itself. Most trivia scripts also have a "KAOS" type question, where no hints are given and there are multiple answers that are divided by *'s such as:

//set %trivia What is 2+2*4*Four

People can answer with both answers and get points for both answers. Obviously, you wouldn't want to give points for 4 and four because they are the same thing, but you can do something like that for other questions.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2005
Posts: 54
B
Babel fish
OP Offline
Babel fish
B
Joined: Oct 2005
Posts: 54
lol, i can't set %x as a specific question because it's reading a file full of them =\
but that helped a ton thanks! ^_^


Chat NSN
My Server: sleepystickman.ircxpro.com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
It was an example. It works fine to use the same method with $read...

//set %x $read(Questions.txt)

Note that in a script, I'd use var rather than set... I was giving an example of it so you could test it outside the script to see how it works.

Also, I just noticed that the board messed up the first "echo" example... If you replace the "bullet" with [[b][/b]*] and place it on the line above to complete the echo line, it will be correct. The board thought I meant to do a list. frown


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard