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

Joined: 29 Dec 2006
Posts: 41
Location: Chester, VT

PostPosted: Mon Jan 01, 2007 6:04 pm   

Array & Map Support
Does cMUD support arrays or maps? If so, can they be multidimensional?

Single Dimension Array:
pub[0] = "Fire & Dragon";
pub[1] = "Amylaar's Tavern";
pubstatus[0] = "INSTOCK";
pubstatus[1] = "SOLDOUT";

Multi-Dimension Array:
pub[0][0] = "Fire & Dragon";
pub[0][1] = "INSTOCK";
pub[1][0] = "Amylaar's Tavern";
pub[1][1] = "SOLDOUT";

pub["FireDragon"] = "INSTOCK";

I'm trying to set up a trigger/status system that will buy healing when I type "heal" from the best pubs for the best prices. Some pubs are sometimes out of stock as well, so I'll need to track that also.
Reply with quote

Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Jan 01, 2007 8:04 pm   
Maps = CMud datarecord variables. @varname.fieldname for simple names or for more complex names %db(varname,fieldname). Datarecord variables aren't that hard to figure out, either. #ADDKEY/%addkey() to add to and modify (these commands overwrite existing keys, rather than ignoring them like their stringlist counterparts), #DELKEY/%delkey() to remove.

CMud supports arrays, but I don't use them. Back in at least older versions of ZMud (when I was still a novice), arrays were more limited forms of simple stringlists. First, they disappeared if you closed your session. Second, there were only like 5 commands and functions that worked with them, and all the knowledgeable gurus and experienced users would simply direct us to the more powerful stringlists.

Mult-dimensional arrays aren't really directly supported by CMud (assuming of course, that CMud arrays are still limited to one dimension). However, datarecords and stringlists can pretty much cover them as well as anything though I suggest the datarecord variable for the two-dimensional ones (anything more than 2 dimensions gets extremely bulky and complicated, but it can be done).

First, set up the datarecord variable. Each fieldname will be a number or some equivalent (if you use actual numbers, you might have to resort to using %db() to access the value as @varname.1 has a different use regarding stringlists and arrays and CMud will think that's what you're trying to do).

Next, each of these number fieldnames will contain a stringlist:


datarecord variable name

You can create a user function easily enough to handle this, although my personal experience with them doesn't extend to CMud yet (in other words, I'm not aware of what needs to be changed and what's still broke or buggy):

#function mdarray($arr,$dim1,$dim2) {%if(%iskey($arr,$dim1),%if(%item(%db($arr,$dim1)),%item(%db($arr,$dim1)),"error: index out of bounds"),"error: index out of bounds")}
EDIT: I didn't like my old signature
Reply with quote

Joined: 29 Dec 2006
Posts: 41
Location: Chester, VT

PostPosted: Mon Jan 01, 2007 8:17 pm   
Awesome, thanks!
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