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
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Fri Jan 16, 2009 7:31 am   

Frustrating database problems... [Solved]
 
All scripts/outputs will be at the bottom.

I've been working with the database for a couple of weeks now. Decided to try something new, and for the most part, I've got it down. There are just a couple problems I cannot seem to solve.

1. The pipeline character, of course, is used to designate a new column, basically. So... Name=Blah blah blah|Level=232|etc... works as intended. The problem I'm having is that sometimes, the name itself contains a pipeline. Now, as you'll see in my script, I've managed to semi-get around it. It's not satisfactory, though, and I wish it to be done the way that it should be done. What's currently happening is that all of the names are encased by quotation marks, so in any view, I see "Blah blah blah" instead of Blah blah blah. I want to get rid of those quotation marks. The problem with that is no matter what I try, it doesn't capture pipelines correctly. I've tried escaping them, no avail. I've tried replacing them, then re-replacing them. No avail. I've even tried using the ascii code for pipelines in a replace. Still didn't work. Take, for instance, (K)(M)(G)(H) \|/ Auspices of the Druids \|/ (1). If I escape the pipeline characters, then it shows up as (K)(M)(G)(H) \~ for the Name. Everything else is lost. If I try any other method I've tried, then it returns: (K)(M)(G)(H) \ for the Name. As you can see, this isn't helpful at all. Any solutions that do not require me to have it quoted in the database itself? Or could this be considered a bug? *sigh*

2. Since it's an equipment database, I'll frequently update the information. The problem is, I don't want to enter in information that's already there, as it's just a redundancy and is not needed. Each item has its own unique serial number, so I'm trying to check to see if the serial number in the script matches a serial number already in the database. I cannot seem to get it to work. I've tried the following:

Code:
#IF %ismember(%1, &SerialNumber) {#SAY "Already in database!"} {Script to add new items here}


That doesn't seem to do jack, despite on the command line, if I type #IF %ismember(####,&SerialNumber) {#SAY True} {#SAY False}, it returns the correct response. So, now I need to figure out how to prevent the addition of already existing information. I would use a comparative variable, but having to go through 300+ records every time I want to update the database is going to be annoying. So, is there a way to correctly identify if an item is already in the database and to skip the remaining steps?

The script is below, with actual output from the MUD below, as well. Any and ALL help is appreciated.

Script
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <class name="SNCapture" copy="yes">
    <trigger priority="11730" copy="yes">
      <pattern>~{/invdetails~}</pattern>
      <value>#NEW MyEq %concat( "Name=", %db( @serialnumbers, %db( @NewItem, "Serialnumber")), "|", @NewItem, "|TotalStats=", @NewItemTS)
NewItem=%null
NewItemTS=0
;#T- "SNCapture"</value>
    </trigger>
    <trigger priority="11740" regex="true" copy="yes">
      <pattern>\{invheader\}(\d+)\|(\d+)\|(\a+)\|\d+\|[+-]?[0-9,]+\|((?:\w+)(?:, \w+)?)?</pattern>
      <value>#VAR NewItem  %concat( "SerialNumber=", %1, "|Level=", %2, "|Type=", %3, "|Wear=", %if( %4, %4, "none"), "|")</value>
    </trigger>
    <trigger priority="11750" regex="true" copy="yes">
      <pattern>\{statmod\}(Wisdom|Strength|Luck|Intelligence|Hit roll|Dexterity|Damage roll|Constitution)\|(\d+)</pattern>
      <value>NewItem=%concat(@NewItem,%replace(%1," "),"=",%2,"|")
#IF (%1="Damage roll" OR %1="Hit roll") { } {#ADD NewItemTS %2}</value>
    </trigger>
    <alias name="datacheck" copy="yes">
      <value>serialnumbers=%null;#T+ "InvDataCheck";invdata</value>
    </alias>
    <trigger priority="11810" copy="yes">
      <pattern>~{/invdata~}</pattern>
      <value>#T- "InvDataCheck"
#LOOPDB @serialnumbers {
  NewItem=%concat( @NewItem, "Name=", %db( @serialnumbers, %key), "|")
  detail %key
  }</value>
    </trigger>
    <var name="serialnumbers" copy="yes"/>
    <var name="NewItem" copy="yes"/>
    <var name="NewItemTS" copy="yes">0</var>
    <trigger name="InvDataCheck" regex="true" copy="yes">
      <pattern>^(\d+),[HMGKI]+,(.*),\d+,\d+,\d+,[+-]?[0-9,]+,[+-]?[0-9,]+</pattern>
      <value>#LOCAL $KeyValue
$KeyValue=%replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %2, "@Y"), "@y"), "@B"), "@b"), "@M"), "@m"), "@G"), "@g"), "@W"), "@w"), "@C"), "@c"), "@R"), "@r"), "@D"), "@d")
#ADDKEY serialnumbers %1 %concat( %char( 34), $KeyValue, %char( 34))</value>
    </trigger>
  </class>
</cmud>


Datacheck Output
Code:
{invdata}
89801902,HKMG,@G\|/ @gAu@Wsp@gic@Wes @gof @Wthe @gDr@Wui@gds @G\|/@w,1,7,1,-1,-1
88083276,HKMG,@CTestament @Wof the @B<(@W=@YWatchmen@W=@B)>@w,121,11,1,-1,-1
1049120,HKMG,a @YBag of @RAardwolf@w,8,11,1,-1,-1
1049044,HKMG,a @YBag of @RAardwolf@w,8,11,1,-1,-1
86633379,HKMG,a @YBag of @RAardwolf@w,8,11,1,-1,-1
{/invdata}


Output running #LOOPDB (using detail)
Code:
{invdetails}
{invheader}89801902|1|Armor|300|1|shield|unique, glow, hum, magic, held, solidified, resonated, v3||The Great Circle of Druids||||
{statmod}Intelligence|1
{statmod}Luck|3
{statmod}Damage roll|6
{/invdetails}
{invdetails}
{invheader}88083276|121|Container|24200|0|back|unique, glow, hum, magic, held, burn-proof, v3||The Watchmen of Aardwolf||||
{container}1500|30|0|0|0|1|50
{statmod}Moves|-120
{statmod}Mana|60
{statmod}Saves|4
{statmod}Luck|6
{statmod}Wisdom|6
{/invdetails}
{invdetails}
{invheader}1049120|8|Container|1000|-66||unique, glow, hum, magic, nosell, held, nopurge, burn-proof, v3, precious|Charneus|||||
{container}1160|100|654|80|64|81|20
{/invdetails}
{invdetails}
{invheader}1049044|8|Container|1000|-66||unique, glow, hum, magic, nosell, held, nopurge, burn-proof, v3, precious|Charneus|||||
{container}1160|100|1119|106|157|106|20
{/invdetails}
{invdetails}
{invheader}86633379|8|Container|1000|-66||unique, glow, hum, magic, nosell, held, nopurge, burn-proof, v3, precious|Charneus|||||
{container}1160|100|746|59|83|60|20
{/invdetails}


Charneus


Last edited by charneus on Sun Jan 18, 2009 4:42 am; edited 1 time in total
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Jan 18, 2009 2:16 am   
 
Well, I figured out how to do the serial number matching, so item 2 is now crossed off.

The answer for that was to use an #IF (%ismember(%1,%dblist(Serialnumber,All))) {blah blah blah}.

Works perfectly. Now, can anyone suggest something for the pipeline character?

Charneus
Reply with quote
shalimar
GURU


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

PostPosted: Sun Jan 18, 2009 2:47 am   
 
could you try... storing the value to a $localvar
it would then seem to be a string list
then maybe pass it %expand($localvar)?
_________________
Discord: Shalimarwildcat
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Jan 18, 2009 3:12 am   
 
$KeyValue=%subregex(%2, "@(?:y|b|m|g|w|c|r|d)?(\|)?","(?(1)¦)")

Use the alternate pipe symbol, it should be the same in nearly all fonts.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Jan 18, 2009 3:58 am   
 
Vijilante: Yours worked nearly perfectly. It still didn't get the \|/ Auspices of the Druids \|/ or an <|Amazonian-Battle-Mask|>. But it matched <*><|Fenris Fangs|><*> and similar items.

By the way, thanks for simplifying the %replaces for me.

Shalimar - give me an example of what you mean. :P

Charneus
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Jan 18, 2009 4:03 am   
 
I love it when I make mistakes and post them. It reminds that I am still human.
$KeyValue=%subregex(%2, "@(?:y|b|m|g|w|c|r|d)|(\|)","(?(\1)¦)")
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Jan 18, 2009 4:15 am   
 
Heh... well, here's what it outputs now:

(?()¦)C(?()¦)r(?()¦)y(?()¦)s(?()¦)t(?()¦)a(?()¦)l (?()¦)E(?()¦)a(?()¦)r(?()¦)r(?()¦)i(?()¦)n(?()¦)g (?()¦)of (?()¦)D(?()¦)i(?()¦)v(?()¦)i(?()¦)n(?()¦)i(?()¦)t(?()¦)y

As you can see... that's not really correct, either. :P I do appreciate all the help you're giving! This time, it only appears on items with the @(whatever) (color codes).

Charneus
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Jan 18, 2009 4:22 am   
 
Hmmm... entering:

Code:
#say %subregex("@G\|/ @gAu@Wsp@gic@Wes @gof @Wthe @gDr@Wui@gds @G\|/@w,1,7,1,-1,-1", "@(?:y|b|m|g|w|c|r|d)|(\|)","(?(1)¦)")


on the command line returns:

Code:
\¦/ Auspices of the Druids \¦/,1,7,1,-1,-1


which is correct. But it doesn't store it in the database correctly... Should I place the %subregex in the trigger that stores the information in the database instead?

Charneus
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sun Jan 18, 2009 4:40 am   
 
Got it... placing it in the trigger that has the #NEW and changing it from %concat("Name=",%db...) to %concat("Name=",%subregex(%db...) worked great.

Thanks again, Vijilante. By the way, your first code was the correct one. So, in thinking that you were wrong, you wound up being wrong. :P

Charneus
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Jan 18, 2009 1:33 pm   
 
The first one had both pieces optional instead of being in an alternation, but had the conditional replacement right. I swapped mistakes with the second one. I have been away from CMud for too long, and am still far too human. I will have to work on both of these maladies.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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