Yes, another Database question

Posted by Loki_edmud on Tue 03 Aug 2004 07:56 PM — 6 posts, 22,271 views.

#0
Ok, I have ready through the Forums but nothing made sense in what I wanted to do.

I wanted to create something like a Buddy List.

Basically I am trying to create a script that add a name of a player to a list of names in a text file.

Then I am trying to make a function that would allow me
load the names from the list and compare and arguement
against the the list of names.

also want something to automatically add a new name to the list if a name is not there, for example if a player introduces themselves to me.

Can someone please direct me to a good exampl of this.

I look ed at the example for Mud Database, a bit complicated for me.

the naems on the text file would be as simple as
errin
draken
wkiki
Bunata
buwawa
USA #1
Do you really need a database for it?
Just use a MC variable, and add a | in between the names. Then to compare, you can just insert the variable (@!namelist) and expand variables, and it'll evaluate like a regular expression.

Your variable contents would be...

joe|bob|nick|phil

Or, if you need data to work a bit differently, you could use an array, you can look at the list of functions for all the array things.
Amended on Tue 03 Aug 2004 10:03 PM by Flannel
#2
Well I hope to in the to possibly addon to this. possibly
store other info later on down the rod tht is when I get back into the swing of things.

possibly like this:

testguy, warrior
testguy2, mage

so not too far down the line after that I could
possibly keep party stats or what not. I would
like to be able to keep this in a text file that
the script could look for at a later time.

I know little about Arrays, I should say I remember little
I know how to wrok with them with in the script. But I have no clue to to have the array save to a txt file
how to add an array automatically, or how i would load the arrays offf the text file.

I just need a clear example I guess, I don't wnat anyone to just give me the answer but I would appreciate it it I were pointed to the right direction of a nice example.
Australia Forum Administrator #3
Have a read about the inbuilt array functions:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=3951

You could use them to store related information, keep it in a variable in a plugin, and the plugin would save its state, thus keeping them on disk when the plugin was not in use.

Or, look at the plugins page:

http://www.gammon.com.au/mushclient/plugins/

Look at the plugin MudDatabase - this shows using an SQL database to store data, this is an alternative approach.
Amended on Thu 05 Aug 2004 09:01 PM by Nick Gammon
#4
Thank you Nick.

This is what I am trying to do just to get a start

I am using THis as the trigger

" * has joined your party"
`This Triggers sends the wildcard
`to my script named "MyTrigger"


sub MyTrigger (name, line, wildcards)
Dim pname, checkname
pname = Wildcards(1)
checkname = ArrayKeyExists ("namelist", pname)
If checkname = TRUE then
world.note " This Person is already on your member's list"
else
ArraySet "namelist", pname 
SetVariable "namelist", ArrayExport ("namelist", ",")
world.note "You have added " & pname & " to your member list"
If ArraySize ("namelist") <2 then
world.note "You currently have " & ArraySize ("namelist") & "member"
else
world.note "You currently have " & ArraySize ("namelist") & "members"
endif
end sub


And of course I am sure that you know that this does not work. I am just not sure what I am doing wrong.
#5
Ok Ok Ok, I am a dummy.

First I would like to take everyone for the help.
Nick You were a Big help. THe answer was right in front of my face. There is an example of what I needed to do in the example script that I am using lol. So this
is what I did:

I am going resuse the code that is in the example script"
AddItem (listname, item) and Ismember(listname, membername)

sub MyTrigger (name, line, wildcards)
Dim pname, listname
listname = "namelist"
If IsMember (listName, pname) then
world.note "You know " & pname & " already !!"
else
AddItem listname, pname
world.note "You have added " & pname & " to the member list."
End if
end sub



Thanks a lot Guys!!