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
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Oct 10, 2004 8:18 pm   

What do you think of this help page?
 
Does it need more? Is it too big and likely to scare people? Should I try to break it into smaller more manageable chunks?

Code:

Advanced Database Scripting
In order to script the database the window must be open and the database must already be created with the proper fields.  Let's start with the whole script and then I will try to explain how it works.  I will use indenting in the larger settings for readability.
#CLASS Identify
#CLASS Identify|IDTrigs
#TRIGGER {Name: &IDedItem.Name} {Affects=""}
#TRIGGER {Type: &IDedItem.Type} {}
#TRIGGER {Cost: &IDedItem.Cost} {}
#TRIGGER {Weight: &IDedItem.Weight} {}
#TRIGGER {Damage: &IDedItem.Damage} {}
#TRIGGER {Hit: &IDedItem.Hit} {}
#TRIGGER {Dam: &IDedItem.Dam} {}
#TRIGGER {Affects (*) by (%n)} {#ADDITEM Affects {%1=%2}}
#TRIGGER {$} {
 #IF (!%null(@IDedItem)) {
  #T- IDTrigs
  #ADDKEY IDedItem Affects {@Affects}
  #DBLOAD ID
  #VIEW All
  #DBFIRST
  #IF (%numrec!="") {
   StoreID
  } {
   CapturingID=%concat( "ID", %secs)
   #VAR @CapturingID @IDedItem {_nodef} {Identify}
   #ADDITEM IDsPending @CapturingID
  }
 }
}
#CLASS Identify
#VAR IDedItem {} {}
#VAR CapturingID {} {}
#VAR Affects {} {}
#VAR IDsPending {}
#VAR ItemSource {}
#TRIGGER {^You get (*) from the coprse of (*).$} {
 #ADDKEY ItemSource {%1} {%zonename() - %2}
}
#TRIGGER {^You pick up (*).$} {
 #ADDKEY ItemSource {%1} {%zonename() - %roomname()}
}
#ALIAS ID {#T+ IDTrigs;#ALARM {+5} {#T- IDTrigs};IDedItem="";cast identify}
#ALIAS StoreID {
 #DBRESET
 CapturingID=%query((&Name=@IDedItem.Name))
 #DBRESET
 Affects=""
 #FORALL @CapturingID {
  #DBGET {%i}
  #IF ((&Type=@IDedItem.Type)&(&Affects=@IDedItem.Affects)) {
   #ADDITEM Affects {%i}
  }
 }
 #IF (@Affects="") {
  #DBRESET
  CapturingID=%query(&Where="New Item")
  #DBRESET
  #IF (@CapturingID) {
   #DBGET {%item(@CapturingID,1)}
  } {
   #NEW All {Where=New Item}
   #DBRESET
   CapturingID=%query(&Where="New Item")
   #DBRESET
   #IF (@CapturingID) {
    #DBGET {%item(@CapturingID,1)}
   } {
    #ECHO Failed to make/find new record in database
   }
  }
  #IF (%rec) {
   #LOOPDB {@IDedItem} {#ADDKEY %rec {%key} {%val}}
   #IF (%iskey(@ItemSource,@IDedItem.Name)) {
    #ADDKEY %rec {Where} {%db(@ItemSource,@IDedItem.Name)}
   } {
    #ADDKEY %rec {Where} {Unknown}
   }
   #DBSAVE
  }
 } {
  #ECHO Item appears to duplicate record%if(%numitems(@Affects)>1,s) @Affects.
  #IF (%numitems(@Affects)=1) {
   #DBGET {@Affects}
   #IF (&Where="Unknown") {
    #IF (%iskey(@ItemSource,@IDedItem.Name)) {
     #ADDKEY %rec {Where} {%db(@ItemSource,@IDedItem.Name)}
     #DBSAVE
     #ECHO Where updated to %db(@ItemSource,@IDedItem.Name).
    }
   } {
    #ECHO Where currently &Where -- source indicates %db(@ItemSource,@IDedItem.Name).
   }
  }
 }
}
#ALIAS OpenIDdb {
 #DBLOAD ID
 #VIEW All
 #DBFIRST
 Affects=0
 #IF (%numrec="") {
  #MENU {Windows|Database}
  #WHILE ((%numrec="")&(@Affects<10000)) {
   #ADD Affects 1
   #DBLOAD ID
   #VIEW All
   #DBFIRST
  }
 }
}
#BUTTON 0 {IDsPending:%if(%btnenable(StoreIDs,%numitems(@IDsPending)),%numitems(@IDsPending),0)} {OpenIDdb;#IF (@Affects!=10000) {IDedItem=@{%item(@IDsPending,1)};#UNVAR %pop(IDsPending) Identify;StoreID} {#ECHO Failed open/load database.}} {} {} {%numitems(@IDsPending)} {} {} {} {} {} {Pos} {1} {880} {32800} {} {Gauge||10|5|0|11} {} "" {} {} {StoreIDs}
#CLASS 0

So what does it all actually do?
First lets follow the steps that it takes when in operation.
 You enter: id whatever
  The alias turns on the triggers class, creates an alarm to turn
  them off for security, blank the main variable, and then sends
  the mud command.
 Since the name trigger is likely to be first we blank the Affects variable here.
 Once a blank line is received we check to see if we got ID information
  When we do: turn of the triggers, put the affects into the main
  variable, then test whether the DB window looks open and ready
  to receive data.  This test is done by checking %numrec, as with
  all database functions when the window isn't open it returns nul.
   If the test succeeds we StoreID otherwise create a variable and
   put the name for it in a list for later storage.
 Storing it in the DB (StoreID):
  First %query to see if there is any items in the DB that look to be the same.
  If it looks to be unique we start storing
   Check for existing blank 'New Item' records
   If we find any we fetch it into %rec
   Otherwise make a new one and fetch it to %rec
   Finally add all the data, I used #LOOPDB and #ADDKEY,
   but this could be done with #NEW instead and be faster.
  Else it looks to be a duplicate report the possible matches.
   If we found only one report or update the Where field and
   the appropiate ItemSource value.
 The StoreIDs button:
  This button is a push/gauge.  It displays the number of pending
  IDs in the caption and also automatically turns off it ability to be
  pushed.
  Script wise it assumes that IDs are stored because the DB wasn't open
  and needs to be opened.  This is done in OpenIDdb.
  If opening the DB didn't timeout of 10000 cycles (on some systems this might
  not be long enough).
   Then it transfers the data to the variable StoreID expects to find it in,
   and cleans up all the temporary variables and lets StoreID do the rest.
  Else it reports the error.
 Opening the DB window and making sure the right DB is loaded:
  First we actually assume the window is open and will respond to
  commands.
  Next test %numrec for nul.
  If it is then we use #MENU to open it.  We only want to do this once.
  Next we loop to give zMud time to open the window and load the database.
  A counter is used to abort the loop and signal error to the button.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Mon Oct 11, 2004 1:49 am   
 
It's useful to see the script as a whole, but the explanations will probably make better sense to most people if the script is split up and each explanation comes right after the segment of script it explains. Perhaps you could do both, by putting the entire script at either the beginning or the end (an Overview page maybe?), with sections of it repeated with each explanation.

Typo: #TRIGGER {^You get (*) from the coprse of (*).$} {
Suggestion: Blank the Affects variable at the same time as the IDedItem variable. There's no good reason to delay it.
Suggestion: You are already using the Affects variable to store information, so you should probably use a different variable to count iterations of #WHILE.
Suggestion: The Identify|IDTrigs class should probably be disabled by default
Suggestion: Instead of giving the button a specific location, use the 'Align Right' option on the Advanced tab (the button was out-of-view until I expanded my zMUD window).
_________________
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.

Last edited by LightBulb on Mon Oct 11, 2004 1:55 am; edited 1 time in total
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Mon Oct 11, 2004 1:52 am   
 
*drool* I can't wait to see the new help files
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Daagar
Magician


Joined: 25 Oct 2000
Posts: 461
Location: USA

PostPosted: Wed Oct 13, 2004 10:15 pm   
 
I don't see a problem with presenting the whole script as you've done here. One glaring problem, however, is that I don't see an example of the mud output that this script is working against :) It would be handy to see various output logs from the mud that this is triggering against. Yes yes, it can be figured out from the triggers, but I feel it gives a better overall picture - especially for someone that wants to adapt something like this for their particular that that will likely have different output.

Otherwise, I agree with the above poster... I look very much forward to these more advanced examples.
Reply with quote
Daagar
Magician


Joined: 25 Oct 2000
Posts: 461
Location: USA

PostPosted: Wed Oct 13, 2004 10:21 pm   
 
Sorry to double reply (where's my edit button?!), but one other comment. I would much prefer to see comments embedded directly in the code. This would more clearly outline the various code blocks and keep the functionality more in-context. Keeps one from needing to contantly scroll back and forth, as well.
Reply with quote
mr_kent
Enchanter


Joined: 10 Oct 2000
Posts: 698

PostPosted: Thu Oct 14, 2004 1:23 pm   
 
I vote for inline remarks and block documentation along with sample mud output. I know...more work. Sad
Reply with quote
dcb
Novice


Joined: 02 Sep 2004
Posts: 42

PostPosted: Sat Dec 04, 2004 7:50 pm   
 
I've tried hard to make this script work and at best i can only get it to half/way function.

My database is called ID and the following fields are present:

Name
Type
Cost
Weight
Damage
Hit
Dam
Affects

The same record keeps getting overwritten and i get the message
Failed to make/find new record in database

If the database is not open the guage moves on the pending and when i click it i get the message

Variable ID49265162 removed. (the variable IDxxxx seems random)
Failed to make/find new record in database

A sample of my mud output is:

You feel informed:
Object 'helmet hades', Item type: ARMOR
Item is: ANTI-GOOD ANTI-NEUTRAL WARRIOR BARBARIAN NoBits
Worn by: Medium races Large races Charmies
Weight: 5, Value: 31000
AC-apply is 8 Resistance to damage is 0
Can affect you as:
Affects : HIT_POINTS By 50
Affects : SAVE_VS_POISON By 2


Would be awesome if we could include the Worn By:

thanks for your help
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