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
Skaphia
Beginner


Joined: 18 Dec 2002
Posts: 27
Location: USA

PostPosted: Fri Jan 31, 2003 4:57 am   

file writing question
 
I have two questions about writing and reading from files. Perhaps you all can find an easy way to do what I need. I play on Realms of Despair and what I want to accomplish first is.. whenever someone gets something from a container I want zmud to log what they got and from what conatiner to a file. Example:

Skaphia gets a crested sword from a silver box.

What would be the commands if the pattern was (%w) gets (%i) from (%c). ?

The second thing I need help with is how can I get a file to return a given command from a random inquiry. For example:

(%w) tells you 'price check on (%i)'

If %i is the random item, how do I get it to look into a file at that item from a list of about 400 different items?

Thanks a bunch,
Skaphia
Reply with quote
Davos
Adept


Joined: 30 Jan 2003
Posts: 228
Location: USA

PostPosted: Fri Jan 31, 2003 5:10 am   
 
As far as writing info to a file, You might want to think about doing it to a database, especially for info on Price Checks, this would make it easier to query and then pull the info from the dB and tell it back to the person that telled you. the first part:

quote:
Skaphia gets a crested sword from a silver box.

What would be the commands if the pattern was (%w) gets (%i) from (%c). ?



The proper pattern to match that line would be:

#TR {^(%w) gets a (%w) from a (%w).} {
@who = %1
@what = %2
@where = %3
}

The only problem with this would be if the line said 'an' instead of 'a' preceding a word that started with a vowel.

The Seaworthy
Reply with quote
Skaphia
Beginner


Joined: 18 Dec 2002
Posts: 27
Location: USA

PostPosted: Fri Jan 31, 2003 5:11 am   
 
Yes but how do I write that line of them taking it out into a text file?
Reply with quote
Davos
Adept


Joined: 30 Jan 2003
Posts: 228
Location: USA

PostPosted: Fri Jan 31, 2003 5:18 am   
 
#FILE 1 sample.txt
#WRITE 1 {@who pulled out a @what from a @where} @recnum

#AD recnum 1


I believe unless you have to do something to make the variables expand prior to writing, not sure

The Seaworthy
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jan 31, 2003 5:23 am   
 
%w is for single words only (no whitespace). You'll probably want * for the item and container (possibly for the name also). You could use %w to match a/an, but that's not really necessary since you're just going to copy the line.
#FILE 1 BigBrother.txt
#TR {%w gets * from *} {#WRITE 1 {%trigger}}

LightBulb
Senior Member
Reply with quote
Davos
Adept


Joined: 30 Jan 2003
Posts: 228
Location: USA

PostPosted: Fri Jan 31, 2003 5:25 am   
 
Heh its amazing how simple it is when you know what your talking about :)
question tho would that example write each trigger instance to a new line or just append it? from what the helpfile says seems it would just append it.

The Seaworthy
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Fri Jan 31, 2003 5:49 am   
 
A quick test indicates that each trigger will be written to another line and also verifies that %trigger is being expanded correctly.

LightBulb
Advanced Member
Reply with quote
Skaphia
Beginner


Joined: 18 Dec 2002
Posts: 27
Location: USA

PostPosted: Fri Jan 31, 2003 5:54 am   
 
That looks like it solves the first problem, even though I still don't know how to plug that into my zmud, still though need a solution for the second one? anyone?
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Fri Jan 31, 2003 1:13 pm   
 
Normally, you could copy and paste the script into zMUD. However, since you need the file to be opened before writing to it, you could either open it yourself everytime it is closed and you need it or have zMUD do it for you. First, copy the line LightBulb posted that starts with #TR and paste it into the command line. Press Enter. The trigger is now created.

Next, copy and paste these next two lines into the command line and press Enter:
#ALIAS atconnect {#FILE 1 BigBrother.txt}
#ALIAS atdisconnect {#CLOSE 1}

The file is named in the alias like LightBulb named it, but you can change the name to whatever you want. Although, the name LightBulb posted is quite accurate for this script, hehe

Ok, now, on to the next problem. Like Davos said, if you have a lot of items with info in a text file, it is a good idea to store all of these in the zMUD database instead and from there you can easily find and item and check it's info. However, I'm thinking that the structure of the items in the file will allow you to avoid this and query the items from within the file itself. There are many ways you can read the item requested from the file, but the method you use depends on how your file is structured. Post a few lines form the file containing the items so we can help you with this.

Kjata
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