|
Berion Newbie
Joined: 10 Nov 2001 Posts: 8 Location: Norway
|
Posted: Sat Nov 10, 2001 9:16 pm
Appending to a certain line in a file |
I'm trying to make a list of alts, characters played by the same person.
The way i want it to work is by storing them in a textfile with one line per person, so that all the alts of each person is stored in the same line so that i can use #type or %grep with one of the names and get the whole list of that persons alts. That part is easy.
The problem is that I want to be able to add to the file. I want to make an alias called 'alts' so that i can type 'alts oldname newname' and it will put in the new name in the line that has the oldname in it.
Is there any way to do that? |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sat Nov 10, 2001 10:21 pm |
quote:
I'm trying to make a list of alts, characters played by the same person.
The way i want it to work is by storing them in a textfile with one line per person, so that all the alts of each person is stored in the same line so that i can use #type or %grep with one of the names and get the whole list of that persons alts. That part is easy.
The problem is that I want to be able to add to the file. I want to make an alias called 'alts' so that i can type 'alts oldname newname' and it will put in the new name in the line that has the oldname in it.
Is there any way to do that?
If you are using a text file as opposed to a database, it looks like you have to read in the entire file, find the line you want, change it, and then write the new entire file back to itself.
I don't recall there being a write function that could pick a line to write to, but I'm not well-versed in file commands in Zscript.
li'l shmoe of Dragon's Gate MUD |
|
|
|
Berion Newbie
Joined: 10 Nov 2001 Posts: 8 Location: Norway
|
Posted: Sun Nov 11, 2001 12:31 am |
How would I make something like this in a database? I haven't used the database much, so i could use some pointers.
So if anyone has any idea how i could make this work, i'd like to know. |
|
|
|
Torrenal Newbie
Joined: 07 Nov 2001 Posts: 2 Location: USA
|
Posted: Sun Nov 11, 2001 5:41 am |
Hmm. I've done the exact same thing in LPC...
The crudest form would be:
#ALIAS altc {#var work %db( @altcs, %1);#var altcs %addkey( @altcs, %1, %2)}
#ALIAS showalts {#show Alts of %1 are~: %db( @altcs, %1)}
It's crude because it I say A is B, there is no record that B is A, but B might
have a record for C...
Let me work at this a bit to get a practical, usable form for you.
//Torrenal |
|
|
|
Torrenal Newbie
Joined: 07 Nov 2001 Posts: 2 Location: USA
|
Posted: Sun Nov 11, 2001 9:05 am |
I don't like the first alias much, but it all works.
Alias: findaltc
Value:
;find record for passed name. return Name & recno
#DBLOAD altcs
#var recno ""
#var name ""
#var lookfor %1
#var lookin %find( @lookfor, altcs, Alts)
#while (@lookin != "") {
#math work {%pos( "|", @lookin) - 1}
#if (@work > 0) {#var lookat %left( @lookin, @work)} {#var lookat @lookin}
#var chars %dbget( @lookat)
#forall @chars.Alts {
#if (%i = @lookfor) {
#var name @chars.Name
#var recno @lookat
#var lookin ""
}
}
#var work %pos( "|", @lookin)
#if (@work > 0) {#var lookin %right( @lookin, @work)} {#var lookin ""}
}
Alias: altsof
Value:
;show the alts of a player
#DBLOAD altcs
findaltc %1
#var chars %dbget( @recno)
#show Alts of %1 are: %replace( @chars.Alts, "|", ", ")
Alias: altc
Value:
;mark 2 players as being alts of each other
#DBLOAD altcs
findaltc %lower( %1)
#if (@name = "") {
#show adding new
#var chars ""
#addkey chars Name %lower( %1)
#addkey chars Alts %lower( %1|%2)
#new All @chars
} {
#var chars %dbget( @recno)
#addkey chars Alts %lower( @chars.Alts|%2)
#dbput @recno @chars
}
#DBSAVE
altsof %1
The Name field in the database is perhaps redundant, but I'd suggest
leaving it in...
I'll admit I first looked at zMud databases tonight, and had to seriously
revise my ideas of how they worked in zMud after my first post. I was also
supprised that I had to keep the database window open for this to work. Is
that a feature or did I manage to foul things up?
//Torrenal
I'll be giving the database doco a closer look tomorrow. |
|
|
|
|
|
|
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
|
|