  | 
	
	
	
		rtatum Novice
 
  Joined: 19 Sep 2004 Posts: 45 Location: Houston
  | 
		
		  
			
			   Posted: Tue Sep 13, 2005 3:14 am   
  Database variable math possible?   | 
			 
			
				Is it possible to increment the value of a key in a database variable somehow?
 
 
Basically I'm trying to keep a list of fish cought, and how many...
 
 
So I get a message like "You reel - a pike - out of the water" and I want to have it increment the value of a key in a database, or some other such thing... | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		Private Adept
 
  Joined: 10 Jan 2002 Posts: 264 Location: USA
  | 
		
		  
			
			   Posted: Tue Sep 13, 2005 4:47 am      | 
			 
			
				yup...
 
 
 
	  | Code: | 
	 
	
	  
 
#TRIGGER {You reel - &Key_name - out of the water} {
 
#LOOPDB @Fish_Database {#IF (@Key_Name = %key} {current_amount = %val;exists = 1}
 
#IF (@exists = 1) {#MATH current_amount @current_amount+1;exists = 0} {current_amount = 1}
 
#ADDKEY Fish_Database @Key_Name @current_amount}
 
 | 
	 
 
 
 
This will add one to an existing record, or create a new record with a value of 1, or some other such thing :P | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		rtatum Novice
 
  Joined: 19 Sep 2004 Posts: 45 Location: Houston
  | 
		
		  
			
			   Posted: Tue Sep 13, 2005 5:24 am      | 
			 
			
				Hate to ask so many questions, but is there a way then to take the database variable, and have it output it to the mud in a say command in this format:
 
 
say Fishkey1: Value Fishkey2: Value Fishkey3: Value and so forth so it'll look like
 
 
Joe says: A pike: 4 A trout: 10 A minnow: 30 | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		nexela Wizard
  
  Joined: 15 Jan 2002 Posts: 1644 Location: USA
  | 
		
		  
			
			   Posted: Tue Sep 13, 2005 5:45 am      | 
			 
			
				Ok There is an easier way to do the first part but too late to test it.
 
 
 
For the second part
 
#HELP %expanddb | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		rtatum Novice
 
  Joined: 19 Sep 2004 Posts: 45 Location: Houston
  | 
		
		  
			
			   Posted: Tue Sep 13, 2005 6:44 am      | 
			 
			
				Got it working, and for future reference, what would the easier way have been?
  | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		Private Adept
 
  Joined: 10 Jan 2002 Posts: 264 Location: USA
  | 
		
		  
			
			   Posted: Tue Sep 13, 2005 10:15 am      | 
			 
			
				prolly without the second #IF??
 
 
 
	  | Code: | 
	 
	
	  
 
#TRIGGER {You reel - &Key_name - out of the water} { 
 
#LOOPDB @Fish_Database {#IF (@Key_Name = %key} {#MATH current_amount %val+1} {current_amount = 1}
 
#ADDKEY Fish_Database @Key_Name @current_amount} 
 
 | 
	 
 
 
 
i wrote it in a hurry :P sue me :) | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		nexela Wizard
  
  Joined: 15 Jan 2002 Posts: 1644 Location: USA
  | 
		
		  
			
			   Posted: Tue Sep 13, 2005 10:27 pm      | 
			 
			
				*Untested* should work with multiple word fish, and doesnt have the overhead that looping statements do.
 
 
#TRIGGER {You reel - (*) - out of the water} {
 
#ADDKEY Fish {%1} {%eval(@{fish.%1}+1)}
 
} | 
			 
		  | 
	
	
	  | 
		  
		 | 
	
	
		  | 
	
	
		| 
		
		 | 
	
	
		 |