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
shalimar
GURU


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

PostPosted: Wed Dec 31, 2003 1:51 am   

Database Variables
 
I am having trouble getting to set up a database veriable within a class from a trigger. The help files never mention how to set one up in a class.

My trigger seems to create the variables fine, however it assumes its just a string list as opposed to a data record. When i went into the settings editor i noticed that the variable auto checks the 'use default value' checkbox even though there is no default value given... once i uncheck this box i can save it as a data record...

#CLASS {Utility|Skins}
#TRIGGER {You ask the furrier if he would like to buy {a|an} (*).} {
#VAR temp {%replace( %1, " ", "_")}
#VAR temp2 {@@temp}
}
#COND {The furrier takes the *, appraises it minutely, then pays you (%d) silvers.} {#IF (%null( @temp2)) {
#VAR @temp {Max=%1|Min=%1} {} {Utility|Skins}
#EC New skin type recorded: @temp
} {
#EC Now we can test for Min/Max!
#IF (%1 > @temp.Max) {#ADDKEY @temp Max %1}
#IF (%1 < @temp.Min) {#ADDKEY @temp Min %1}
}} {within|param=1}
#CLASS 0


PS. once i got the variable properly saved i looked at the 'class script' again and notice that the syntax used to display the database variable is nothing like how the help files say to create it:

#VAR viper_fang {Max528Min148}

PPS. when i displayed it another way it appears in yet a third syntax (#VAR with no parameters):

viper_fang Max<30>528<29>Min<30>148
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Wed Dec 31, 2003 4:28 am   
 
Try:
#VAR @temp {Max=%1|Min=%1} _nodef {Utility|Skins}
Reply with quote
shalimar
GURU


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

PostPosted: Wed Dec 31, 2003 6:02 am   
 
#VAR @temp {Max=%1|Min=%1} _nodef {Utility|Skins}
this is just some filler material ok everyone^ syntax error

It did still correctly save the variable to the class. The issue remains that it is a 'string list' upon creation and not a 'data record'.
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Wed Dec 31, 2003 6:33 am   
 
Add to the value of your trigger:

#IF (!%defined(@temp)) {#VAR @temp {} _nodef "utility|skins"}
#ADDKEY @temp {Max=%1|Min=%1}

ie. Lets check to see if it exists, if not create it.
Then use #ADDKEY to force data record.

Edit:
Probably a better check; takes into account the folder, something like

#VAR temp tester2
#VAR temp2 ./utility/skins/@temp
#IF (%null(@{@{temp2}})) {#VAR @temp {} _nodef "utility|skins"}

#VAR @temp2 %addkey(@{@temp},Min,%1)
#VAR @temp2 %addkey(@{@temp},Max,%1)

Odd forum c[/b]orruption with last bold Smile
Reply with quote
shalimar
GURU


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

PostPosted: Wed Dec 31, 2003 8:36 am   
 
I finally got it to work with the following code:

#CLASS {Utility|Skins}
#ALIAS testfur {#EC You ask the furrier if he would like to buy a test fur.;#EC The furrier takes the test fur, appraises it minutely, then pays you %1 silvers.}
#VAR test_fur {Max765Min45}
#TRIGGER "skinvalue" {You ask the furrier if he would like to buy {a|an} (*).} {
#VAR temp {%replace( %1, " ", "_")}
#VAR temp2 {@@temp}
}
#COND {The furrier takes the *, appraises it minutely, then pays you (%d) silvers.} {#IF (%null( @temp2)) {
#VAR @temp {} _nodef "utility|skins"
#ADDKEY @temp Max %1
#ADDKEY @temp Min %1
#EC New skin type recorded: @temp
} {
#IF (%1>%db( @{@temp}, Max)) {
#EC Increased profit by %exec( %1-%db( @{@temp}, Max)).
#ADDKEY @temp Max %1
}
#IF (%1<%db( @{@temp}, Min)) {
#EC Sales are down by %exec( %db( @{@temp}, Min)-%1).
#ADDKEY @temp Min %1
}
}} {within|param=1}
#CLASS 0

However there seems to be a small issue with the #ECHO lines, I am getting this output:

Increased profit by 755-745.
Sales are down by 45-545.

Any ideas?
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Wed Dec 31, 2003 8:48 am   
 
Try %eval vs %exec?
Reply with quote
shalimar
GURU


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

PostPosted: Wed Dec 31, 2003 9:32 am   
 
That did it, thanks alot... now to put it to use.

One other thing, is there a way i can force the trigger back to its initial state if the object i try to sell isn't a skin? (Set into another trigger of course.)

#TR {The furrier frowns and says "I haven't a clue, &Me. I only deal furs, skins and other valuable bodily parts."} {What goes here to reset "skinvalue"?}
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Dec 31, 2003 12:39 pm   
 
#STATE skinvalue 0
Reply with quote
shalimar
GURU


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

PostPosted: Wed Dec 31, 2003 10:21 pm   
 
Another issue ive noticed, hyphenated strings seem to break the code and get rerouted to the main directory, eg: "a rune-etched golden sphere"
Reply with quote
shalimar
GURU


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

PostPosted: Sun Jan 11, 2004 3:44 am   
 
Hmm database variables are nice and all but im finding this is creating way to many variables for my taste, could anyone help me convert this trigger class into a normal database?
Reply with quote
solem
Beginner


Joined: 16 Mar 2004
Posts: 20

PostPosted: Wed Jan 05, 2005 8:10 pm   
 
I don't seem to beable to delete this. Confused
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Thu Jan 06, 2005 3:32 am   
 
Create a database (Skins) with three fields (Name, Max, Min).
Check whether a record already exists.
If so, update the record.
If not, create a new record.

Something like this (untested):
Code:

#CLASS {Utility|Skins}
#TRIGGER "skinvalue" {You ask the furrier if he would like to buy {a|an} (*).} {#VAR tempSkins {%query( &Name = "%1", All|sk)}}
#COND {The furrier takes the *, appraises it minutely, then pays you (%d) silvers.} {
#IF (@tempSkins) {
#DBPUT %item( @tempSkins, 1) Max {%max( %db( %item( @tempSkins, 1), Max), %1)}
#DBPUT %item( @tempSkins, 1) Min {%min( %db( %item( @tempSkins, 1), Min), %1)}
} {
#VAR tempSkins ""
#ADDK tempSkins Name {%t1}
#ADDK tempSkins Max {%1}
#ADDK tempSkins Min {%1}
#NEW All|sk @tempSkins
}
#VAR tempSkins ""
}
#TR {The furrier frowns and says "I haven't a clue, &Me. I only deal furs, skins and other valuable bodily parts."} {#VAR tempSkins "";#STATE  skinvalue 0}
#CLASS 0

When using database variables, it isn't necessary for each skin to have its own variable. It would be far simpler to have two database variables, SkinsMax and SkinsMin, with each variable using the names as keys. Slightly more advanced would be a single database variable using the names for keys and the Max|Min in a stringlist for the values.
_________________
LightBulb
Senior member

Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious.
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