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
trak
Newbie


Joined: 21 Jan 2002
Posts: 7
Location: Canada

PostPosted: Mon Mar 18, 2002 9:50 pm   

Modifying DB records from within a script
 
My problem concerns modifying records stored in the database from within a script. The particular MUD I play has certain pieces of equipment that can have varying stat modifiers. What I want to do is capture the output from an identify spell, and if the object being identified has better stat modifiers than the one currently in the database, update the database. The problem is that when I try to modify a field in a record, the field is set to zero.

Here's an example of what I mean:

Object 1 and 2 are the same name, but have different modifers.

Object 1:
quote:

...
Affects strength by -1.
Affects hitroll by 4.
Affects dexterity by 3.


Object 2:
quote:

...
Affects strength by -3.
Affects hitroll by 4.
Affects dexterity by 1.



The following trigger captures the modifiers:
#TRIGGER {^Affects (%w) by (*).$} {#addkey Item {%proper( %1)=%2};#additem TweakList {%proper( %1)}}

@NegativeStats contains a list of modifiers that are better the lower they are (eg. AC, Svspell)

quote:

@CurrentRecord = %find( %db( @Item, Name))
#if (%null( @CurrentRecord)) {
#NOOP Item doesn't exist, so add it.
#NEW All @Item
} {
#DBGET @CurrentRecord
#FORALL @TweakList {
@CurrentTweak = %db( %rec, %i)
#if (%ismember( %i, @NegativeStats)) {#if (@CurrentTweak > %db( @Item, %i)) {
#NOOP Lower means better here, so change it.
#ADDKEY %rec {%i=%db( @Item, %i)}
}} {#if (@CurrentTweak < %db( @Item, %i)) {
#NOOP Higher number (and better in this case), so change it.
#ADDKEY %rec {%i=%db( @Item, %i)}
}}
}
}
@TweakList = ""
@Item = ""



I think the problem is in "#ADDKEY %rec {%i=%db( @Item, %i)}". Is this a valid way to update a record? If not, can someone suggest another way to do it?

Sorry for the long post, but I didn't want to leave anything out. Thanks in advance. :)
Reply with quote
Daagar
Magician


Joined: 25 Oct 2000
Posts: 461
Location: USA

PostPosted: Tue Mar 19, 2002 3:43 am   
 
I've just begun to explore the DB, but have you tried looking at #DBPUT?
Reply with quote
trak
Newbie


Joined: 21 Jan 2002
Posts: 7
Location: Canada

PostPosted: Tue Mar 19, 2002 6:50 pm   
 
Yup... that does it. Thanks
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