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
daren
Beginner


Joined: 25 Aug 2002
Posts: 13
Location: Australia

PostPosted: Sat Jul 26, 2003 1:57 pm   

help with a shop inventory management script
 
Hi, i'm trying to create a trigger/script that will read what's for sale in a shop, and using a database scan the it and find if there is a item allready listed, if there is it'l update the number for sale, if there's less then it'l record the difference as sold, if more it'l just update it, i'm having some trouble with this since i'm unfamiular with the db, and i am getting many different responses.



*:%s(*) (%d)%s(%d)gp

that is the pattern i am using to match it

#PRI {
#loopview {#if (&item = %1) {
#if (&price <> %3) {&price = %3}
#if (&numberforsale < %2) {
#math &numberssold &numberforsale-%2
&numberforsale = %2
#var foundrec 1
} {#if (&numberforsale >%2) {
&numberforsale = %2
#var foundrec 1
} {#if (&numberforsale = %2) {#var foundrec 1} {}}}
} {}}
}
#if (@foundrec = 0) {#new sh {item=%1|price=%3|numberforsale=%2}}
#var foundrec 0

and that is the code i have used so far,

any assistance or advice would help for right now that code does nothing but add one record, with the item being the first item listed, and the price and number for sale relating to the last item listed

glen
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Jul 26, 2003 7:41 pm   
 
Your biggest problem appears to be in the comparison
#IF (&item = %1)
Since this is a string, you need to ensure that the #IF is using a string comparison. Also, since %1 is the match from an * it might include leading or trailing spaces. These should be removed using the %trim function, which will also identify it as a string comparison.
#IF (&item = %trim( %1))

I wasn't sure what the result of using #MATH with &fieldname would be, so I used a temporary variable (@sold) instead.

Your script can be simplified quite a bit. In all cases where &item matches %1 you want @foundrec to equal 1, so all the #VAR foundrec 1 statements can be combined. Likewise, you always want &numberforsale to equal %2 so all the &numberforsale = %2 statements can be combined once you've completed your calculations for &numberssold.

The opening * in the pattern is unnecessary.

You want the entire trigger to finish before processing the next line, so I've included the entire script in the #PRIORITY. Hopefully I got all the () and {} matched up correctly.

#TR {:%s(*) (%d)%s(%d)gp} {
#PRI {
#LOOPVIEW {
#IF (&item = %trim( %1)) {
&price = %3
#IF (&numberforsale > %2) {
#MATH sold (&numberforsale - %2)
&numberssold = @sold
}
&numberforsale = %2
#VAR foundrec 1}}
#IF (@foundrec = 0) {#NEW sh {item=%trim( %1)|price=%3|numberforsale=%2}}
#VAR foundrec 0}}

NOTE: While some portions of this script have been tested, it has NOT been tested as a whole.
Reply with quote
daren
Beginner


Joined: 25 Aug 2002
Posts: 13
Location: Australia

PostPosted: Sat Jul 26, 2003 10:13 pm   
 
It works better now however when it reads items that are allready there it seems to get the incorrect numberforsale value the second time around i'm not that good at triggers and the problem is way behond me
Reply with quote
daren
Beginner


Joined: 25 Aug 2002
Posts: 13
Location: Australia

PostPosted: Sat Jul 26, 2003 10:21 pm   
 
ok, it seems that after it matches the name it reverts everything else back to the last recored saved, instead of the matched record
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