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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
jcmcbeth
Beginner


Joined: 18 Sep 2008
Posts: 13
Location: Charlotte, NC

PostPosted: Thu Sep 18, 2008 2:14 am   

Database Problems
 
I have some input like this, and I have a trigger that fires for each line. I want to store this in a database.

Code:

Name            Starsystem    Governed By                Pop      Type
Doma            Mako          Shinra                     100.0           Planet   
Figaro          Mako          Shinra                     100.0           Planet   
Cullandor       Tartarus      Shinra                     100.0           Planet   
Citadel         Prime         Solarian Expedition        84.0           Planet   
Solaria         Prime         Solarian Expedition        100.0           Planet   
New sol         Prime         Solarian Expedition        100.0           Planet   
Solaris         Prime         Solarian Expedition        100.0           Planet   
Erf             Prime         Solarian Expedition        100.0           Planet   
Sanctum         Haven         Solarian Expedition        100.0           Planet   
Buck            Haven         Solarian Expedition        100.0           Planet   
Tranquil        Haven         Solarian Expedition        100.0           Planet   
Minerva         Haven         Solarian Expedition        100.0           Planet   
Solgarde        Haven         Solarian Expedition        97.0           Planet   


So, I do something like

Code:

$p_rec = %find(%1, "All", "Name");

#SHOW $p_rec;
#SHOW %1;

#IF ($p_rec == "") {
  $new_rec = {Name=%1|System=%2|Clan=%3|Support=%4|Type=%6};
 
  #NEW Planet $new_rec;
}


Where Planet is the database and All is the view. This only works for the first record, as the %find will return nothing every time it is called afterwords even though the trigger will fire for each line. But if I go to the commandline and say #SHOW %find("Erf", "Planets", "Name") it will return the db record immediately.

I've been trying to look through the documentation, but it isn't very helpful, if this doesn't work I don't understand how you add something to the database without adding a duplicate, how to check if a single entry exist in the database, or retreive a single entry from the database.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Thu Sep 18, 2008 4:17 pm   
 
What exactly do you mean by "not working"? From the sounds of it, you mean that it is making a new entry for every succeeding line, even though there is already a matching entry?

What you probably want is the #Addkey command. With that, you don't even have to check for uniqueness. From the documentation:
Quote:
Adds a key=value pair to a record variable. Record variables are a list of key properties, each with a value. Key must be unique. Any existing value for the given key is replaced with the new value.
Reply with quote
Toxic
Adept


Joined: 27 May 2008
Posts: 299

PostPosted: Thu Sep 18, 2008 4:50 pm   
 
Heh I didn't even know that MUD was still around... whats it called Federation? I got my start mudding with Federation back when it was on AOL and you had to pay for every hour you were on AOL... Tough times for mudders.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4690
Location: Pensacola, FL, USA

PostPosted: Thu Sep 18, 2008 8:38 pm   
 
#TR {^(%w)%s(%w)%s(*)%s(%d)%s(%w)$} {$name=%param(1);$starsystem=%param(2);$goverend=%param(3);$population=%param(4);$type=%param(5)}

that will make a local var to capture each segment... looks like he wants a true DATABASE and not a DBvar though.. out of my scope
_________________
Discord: Shalimarwildcat
Reply with quote
jcmcbeth
Beginner


Joined: 18 Sep 2008
Posts: 13
Location: Charlotte, NC

PostPosted: Fri Sep 19, 2008 5:15 pm   
 
Code:
$p_rec = %find(%1, "All", "Name");


Will only return the ID for the first line for that mud output even though the trigger is fired for each subsequent line. Everyone other time the trigger is fired %find will return "" instead of the ID even though those records are already in the database so it just keeps adding those records.

Quote:
Heh I didn't even know that MUD was still around... whats it called Federation? I got my start mudding with Federation back when it was on AOL and you had to pay for every hour you were on AOL... Tough times for mudders.


Actually this is an SWR 2.0 called Planets: Sol Setting or something.
Reply with quote
jcmcbeth
Beginner


Joined: 18 Sep 2008
Posts: 13
Location: Charlotte, NC

PostPosted: Fri Sep 19, 2008 5:32 pm   
 
I actually did try to implement this problem with a bunch of database variable, but I couldn't figure out how to take an alias argument and use it has the name of a variable, such as:

Code:

#ALIAS Go {
   $str = "@"%1;
   $var = %eval($str);
}


I believe this is what I did and then zmud would always crash when it tried to evaluate that. Although I guess this is another topic.
Reply with quote
Toxic
Adept


Joined: 27 May 2008
Posts: 299

PostPosted: Fri Sep 19, 2008 5:49 pm   
 
Code:
#ALIAS go {$var = @{%1}}

Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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