Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Feb 21, 2008 4:15 pm   

Help Me With Data Record Variable Please
 
Okay, I started playing this old mud I used to play a lot. In this mud you cannot refer to your potions by name but you must use numbers for everything. What I did was create string lists for each type of potion that stores the potion numbers for that specific potions. In other words I have a stringlist called HealthPotions with "1234|2343|53432|2341" and so on with every other type of potion. Then once again since I can't refer to potions by name I just sip a random potion from that list like this:

Code:


Alias: Sip
Value:
$type=@{%proper(%1)Potions}
$sipped=%item($type,%random(1,%numitems($type)))
#if (%numitems($type) > 0) {
  #send {sip $sipped}
  sipping=%proper(%1)Potions
  lastsip=$sipped
  }


I track which potions I just sipped and which exact potion I used and store them. Why? Because when that potion empties out I trigger off the empty message to do this:

Code:

$sipped=%1
#if ($sipped=@lastsip) {
  #delitem @sipping @lastsip
  #say {$sipped removed from @sipping}
  }


What I want to know is how do I convert all this to one data record variable that uses stringlists for the potion numbers. Like the data record would be Potions then would contain the keys Health, Mana, and so on and the value of Health would be a stringlist. I guess the reason I want to is so I don't have 50 stringlists of different types of potions. Maybe I should leave it like I have it?

How do I add each potion number to Health and how do I remove one at a time? Also how would I convert that to my random sip? I think I did this before, but my memory sucks today and I can't seem to do it. Every time I try using #additem it just converts the entire record of potions to a stringlist instead of a datarecord containing stringlist values.
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Feb 21, 2008 5:44 pm   
 
Code:
#VAR Potions {}
#ADDKEY Potions Health "1234|2343|53432|2341"


Code:
#ALIAS sip($potion) {
$vials = %db(@Potions, $potion)
#IF (%numitems($vials) > 0) {
  $sip = %item($vials, %random(%numitems($vials)))
  #SEND {sip $sip}
  sipping = $vials
  lastsip = $sip
}
}


I'll leave the last part for you or someone else to figure out, but I hope this helps a little. Smile
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Feb 21, 2008 6:02 pm   
 
I know how to add them all at once like that. Problem is I have to add them from my potionlist trigger lines.

If I do:

Code:
#addkey Potions Health %1


Then the next line with a health potion will just overwrite the first value since it will only allow one value. The way you add them I understand. I just can't remember how to add one at a time to that value.

For example, I receive lines that say:

"blue potion1234" Type: Health Restoration Sips: 40
"pink potion2345" Type: Mana Restoration Sips: 40
"blackpotion6254" Type: Vigour Sips: 40
"brown potion3324" Type: Health Restoration Sips: 40


So I want to add both of those health potions to Health in a stringlist. I guess I could add and store them all up in local variables and then just #addkey Potions Health $healthlist. Sorry I am sure this is easy. I know I did this very easily when I did it last time. I just can't remember **** today. By the way I want the keys permanently stored. It gives me a record of all the potions available as well, which is why right now I have a multitude of stringlist variables for each type I wanted to compress into a database.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Feb 21, 2008 6:29 pm   
 
Code:
#addkey Potions Health {%additem(%1,%db(@Potions,Health))}

_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Feb 21, 2008 6:34 pm   
 
Haha! I knew it was something so simple. Duh forgot all about %concat.

Edit: Ha you edited that. Thanks! That last one is exactly what I used last time. I lost all my files though so am having to try and remember everything I did. Still it was simple but I couldn't damn well remember.


Last edited by oldguy2 on Thu Feb 21, 2008 6:37 pm; edited 1 time in total
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Feb 21, 2008 6:36 pm   
 
Heh, I snuck in behind you and changed it to %additem
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Feb 21, 2008 6:38 pm   
 
I noticed! That last post is what I did last time. Thanks.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Feb 21, 2008 7:16 pm   
 
By the way Larkin, your example won't work. It will sip nothing as well as something and it also records every potion you sipped in sipping variable.

This does though. It will only sip what you actually have and store only the last one sipped.

Edit: The "sipping" variable should store the type not a stringlist of all the potions sipped. Lastsip should only store the very last potion number used.

Code:

$type=%proper(%1)
$potions = %db(@Potions, $type)
#IF (%numitems($potions) > 0) {
  $sipped = %item($potions,%random(1,%numitems($potions)))
  #SEND {sip $sipped}
  sipping = $type
  lastsip = $sipped
  }
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu Feb 21, 2008 10:02 pm   
 
My code was based on your original code, which was incorrect. I was wondering why you wanted to track a string list of vials in the sipping variable, but it's your script and not mine. Razz
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu Feb 21, 2008 11:10 pm   
 
Actually the original code worked just as it should have.

Sipping became sipping=%proper(%1)Potions or sipping=HealthPotions to store the type of potions I just sipped as HealthPotions. :-) I am sure it looks like crap to experts but hey I try. Very Happy
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Fri Feb 22, 2008 4:08 pm   
 
You're right. I misread that line (unless you stealthily edited the post, heh). Anyway, glad you got what you needed!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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