mIRC Homepage
Posted By: ScottRoberts Pulling from Text Files...again - 23/12/02 04:26 AM
I have a text file that someone gave me with riddle in it. When a user types riddle or !riddle, I want to pull the riddle and theh answer from the file.

The file is currently laid out so that each riddle takes two lines...the first line is the riddle, the second the answer.

When the user type riddle (or !riddle, I want to pull the riddle...wait about 3 seconds then have the answer put out.

How would I do that..or is it even possible,

Thanks for your help. cool
Posted By: acemiles_ed Re: Pulling from Text Files...again - 23/12/02 04:29 AM
Try something like:
(You need to mark every riddle line to start with: Riddle
Code:
 
on *:TEXT:!riddle:*:{
/msg $nick $read(riddle.txt, s, Riddle)
/timer 1 10 /msg $nick $read(riddle.txt, $calc($readn + 1))
}
 


Not tested, but that should do the trick.

riddle.txt should be setup like:
Riddle This is the actual riddle
Answer to riddle

(ty collective)
Posted By: Collective Re: Pulling from Text Files...again - 23/12/02 04:39 AM
That would be on TEXT, not on TEST smile
Posted By: ScottRoberts Re: Pulling from Text Files...again - 23/12/02 05:00 AM
Okay..that works, but what if I have more than one riddle in a file? Would I just be best to have the riddle and answer on one line, it can it randomly pull from the ODD numbered lines in the file to get the riddle and hten the Even number to get the answer....I may be asking too much....
Posted By: acemiles_ed Re: Pulling from Text Files...again - 23/12/02 05:11 AM
Well... if you add the word "Riddle" in front of every riddle... that script should randomly pick any line starting with Riddle. It will then wait 10 secs to /msg the answer (which is on the next line)
Posted By: Cheech Re: Pulling from Text Files...again - 23/12/02 05:16 AM
perhaps you could make another .txt file for the answers and use the $readn to call the answer from there ?
for instance
Code:
 
 
 on *:TEXT:!riddle:*:{
/msg $nick $read(riddle.txt)
/timer 1 10 /msg $nick $read(amswer.txt,$readn)
}
 


that would read a randome line from riddles.txt and then read the coresponding line in answer.txt but riddle 1 and answer 1 would have to each be on line one of thier respective files .
i havent tested it but it should work
Posted By: Cheech Re: Pulling from Text Files...again - 23/12/02 05:19 AM
with the s switch in the $read command line would it pull a random line or the first line with riddle in it ? havent used it much just curious ? i was of the thinking it would always hit the first line starting with riddle ?
Posted By: acemiles_ed Re: Pulling from Text Files...again - 23/12/02 05:36 AM
Cheech brought up a good point.. using the s switch, it would always pull the first one it found =/

His idea of putting them into two files in theory would work. Just make sure you have the answer and the question on the same corresponding line.
Posted By: Collective Re: Pulling from Text Files...again - 23/12/02 05:36 AM
Cheech is right, it does only hit the first line..

Code:
on *:TEXT:!riddle:#:{
  var %riddle = $read(riddle.txt)
  if ( $right($readn,1) == 0 ) || ( $right($readn,1) == 2 ) || ( $right($readn,1) == 4 ) || ( $right($readn,1) == 6 ) || ( $right($readn,1) == 8 ) {
    set %answer %riddle
    set %question $read(riddle.txt,$calc($readn - 1))
  }
  else {
    set %question %riddle
    set %answer $read(riddle.txt,$calc($readn + 1))
  }
  msg # Riddle: %question
  .timer 1 10 msg # Answer: %answer
}


^That will work. Riddles need to be on odd numbered lines, and the answers on the even ones after them.
© mIRC Discussion Forums