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
atraeyu
Novice


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";

Maps:
pub["FireDragon"] = "INSTOCK";
pub["AMYLAAR"] = "SOLDOUT";

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
MattLofton
GURU


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:

Code:

datarecord variable name
------------------------------
1)x1y1|x2y1|x3y1|x4y1
2)x1y2|x2y2|x3y2|x4y2
3)x1y3|x2y3|x3y3|x4y3
4)x1y4|x2y4|x3y4|x4y4
5)x1y5|x2y5|x3y5|x4y5
N)x1yN|x2yN|x3yN|x4yN


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
atraeyu
Novice


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 Wolfpaw.net