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


Joined: 25 May 2010
Posts: 14

PostPosted: Wed Jun 09, 2010 6:47 am   

getting a list from a variable
 
I'm going to do my best to explain this...and hope it makes sense to some one.

I have a series of variables that look like
Code:
sketchbook41202
sketchbook212355
sketchbook12341

which each contain a list of numbers.

I also have a list called sketchbook_list that contains the numbers after each sketchbook (so it contains 41202|212355|12341).

I'm trying to figure out a way to make it so that I can run through all the numbers in @sketchbook_list and put it at the end of @sketchbook so that I can use it in a %ismember function to see if the value of @sketch (which is a number and is in one of the sketchbook lists that I posted above, I just don't know which one very easily) is in one of the lists, and if so, which list it is, and then assign that number from @sketchbook_list to current_sketchbook. The problem is, it doesn't register @sketchbook%i as being the list....

For example, if %i was currently equal to 41202, then instead of it pointing to the variable list for sketchbook41202 and checking to see if @sketch is a member of the list @sketchbook41202, it just looks and sees if @sketch and then doesn't even register the @sketchbook41202 as a list, just as a single variable. If that makes sense...

Well, here's my code so far. I've played around with numerous things, but it all points back to the fact that I can't seem to use the @sketchbook_list numbers to use %ismember with @sketch.

Code:
#FORALL @sketchbook_list {
    #IF (%ismember(@sketch, @sketchbook%i)) {
      #VARIABLE current_sketchbook sketchbook%i
    }
  }


Is there another way of doing what I'm trying to do? Any help would be appreciated.
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Wed Jun 09, 2010 7:43 am   
 
Using @{sketchbook%i} should work.
Reply with quote
Stevestones01
Beginner


Joined: 25 May 2010
Posts: 14

PostPosted: Wed Jun 09, 2010 7:48 am   
 
worked perfectly, thank you!
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Wed Jun 09, 2010 8:03 am   
 
On the topic of sketches, I do happen to have a method for handling them. It might be considered a little more advanced as it uses lists nested in a database variable.

Sketchbooks: A database variable with every sketch in all of your books as keys and their corresponding books as values.
Code:
<var name="sketchbooks" type="Record">sketch76321=sketchbook6834|sketch4321=sketchbook7055|sketch103932=sketchbook3635|sketch94214=sketchbook3941|sketch92834=sketchbook5442|sketch104123=sketchbook6406</var>


Sketches: A database variable with a key for each type of sketch and a list of sketches of those types as values.
Code:
<var name="sketches" type="Record">deldreth="sketch103932|sketch4321|sketch92834"|banshee="sketch76321|sketch94214"|spider=sketch104123</var>


Tear: An alias which takes the type of sketch you want and tears one from the correct book.
Code:
<alias name="tear">
  <value>$sketch = %item( %db( @sketches, %1), 1) $book = %db( @sketchbooks, $sketch) ~tear $sketch from $book</value>
  </alias>


Entire code:
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <class name="Sketches">
    <alias name="tear">
      <value>$sketch =  %item( %db( @sketches, %1), 1)
$book =  %db( @sketchbooks, $sketch)
~tear $sketch from $book</value>
    </alias>
    <var name="sketches" type="Record">deldreth="sketch103932|sketch4321|sketch92834"|banshee="sketch76321|sketch94214"|spider=sketch104123</var>
    <var name="sketchbooks" type="Record">sketch76321=sketchbook6834|sketch4321=sketchbook7055|sketch103932=sketchbook3635|sketch94214=sketchbook3941|sketch92834=sketchbook5442|sketch104123=sketchbook6406</var>
  </class>
</cmud>
Reply with quote
Stevestones01
Beginner


Joined: 25 May 2010
Posts: 14

PostPosted: Wed Jun 09, 2010 8:30 pm   
 
if I wanted to try your code out, how would I go about entering it into cmud? It's in xml so I'm guessing I can't just copy and paste the thing into the command line and have it make the classes and triggers automatically. So should I just try and rewrite it all as zscript?

Sorry, I'm completely new to databases and it seems like they could be very useful so I'm trying to learn them :D
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Wed Jun 09, 2010 9:36 pm   
 
Actually, that code can be treated as if you copied a trigger/var/alias straight from the package editor. Simply paste it wherever you want in the tree view on the left. When you copy a setting from your package editor, cmud is really copying the XML code to the windows clipboard.

Feel free to contact me in-game as Aedius.
Reply with quote
Stevestones01
Beginner


Joined: 25 May 2010
Posts: 14

PostPosted: Wed Jun 09, 2010 9:59 pm   
 
Alright, I will, but you don't seem to be on right now... so I have one more question that hopefully some one can answer.

I managed to do the sketchbook variable just fine and have it up and running to record all the sketches as keys and it's corresponding sketchbook as the value. But I can't seem to get the other thing to work. The one for the variable sketches.


I'm trying to use the same way I did with the sketchbook variable..which is
Code:
#ADDKEY sketches spider %1

The problem is instead of it just adding more and more values to the spider key, it just replaces the old value in spider with the new one.

What would be the function to add onto the list, rather than replace it?
Reply with quote
GeneralStonewall
Magician


Joined: 02 Feb 2004
Posts: 364
Location: USA

PostPosted: Wed Jun 09, 2010 10:17 pm   
 
The way to do it would be: #addkey sketches %additem( %1, %db( @sketches, spider))
Then to remove an item: #addkey sketches %delitem( %1, %db( @sketches, spider))
Then if you didn't want duplicates you'd add an #if (!%ismember( %1, %db( @sketches, spider)) beforehand.

Like I said, this is why it's a bit more complicated. Though, making both of those a user-defined function or alias would make it less convoluted. What's nice is in the future 3.x versions you'll be able to do #additem sketches.spider %1, but for now you must use the above. This is just a suggestion and in no way the end-all method.
Reply with quote
Stevestones01
Beginner


Joined: 25 May 2010
Posts: 14

PostPosted: Thu Jun 10, 2010 12:09 am   
 
ok, all that's working perfectly and I just have one more question. It isn't really necessary, just a bonus. I was wondering if there is a way to tell how many values are under a certain key in a variable database. I was looking at the %numkey() and %numrec() functions, but I don't think either are what I need.


Edit: Nevermind, I got it working
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