Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
TerrellKl
Novice


Joined: 30 Aug 2005
Posts: 49

PostPosted: Wed Jan 04, 2006 1:11 am   

reading from a text file
 
I made a trivia script
I have a txt file full of trivia questions and answer but i'm not sure how to extract the questions/answers

How was your day?*awesome
is the format that the trivia questions are in
is there a way to randomly select a line, set a question variable to what comes before the * and a answer variable to everything after the *?

thank you for your time

I need an opposite of concat really..
to split the line into How was your day? and awesome
Help please
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Wed Jan 04, 2006 1:59 am   
 
#FILE 1 trivia_text_file_name_in_your_zmud_directory.txt

#VAR A_Question %read(1,%random(1,%filesize(1))
#VAR A_Answer %copy(@A_Question,%pos("*",@A_Question)+1,%len(@A_question))
#VAR A_Question %copy(@A_Question,1,%pos("*",@A_Question)-1)

say @A_Question
say @A_Answer

Something like that should work. This solution has no memory of questions asked though.
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Wed Jan 04, 2006 2:51 am   
 
You're looking for %word()

Code:

#file 1 "yourfile.txt"
question=%word(%read(1,@line),1,"*")
answer=%word(%read(1,@line),2,"*")
Reply with quote
TerrellKl
Novice


Joined: 30 Aug 2005
Posts: 49

PostPosted: Wed Jan 04, 2006 5:15 am   
 
got it to work thx gamma
you also helped tondiening but gamma_rays way is easier for me
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
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

© 2009 Zugg Software. Hosted by Wolfpaw.net