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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
surge4883@yahoo.com
Beginner


Joined: 30 Jul 2010
Posts: 19

PostPosted: Fri Jul 30, 2010 11:58 pm   

variable matrix
 
I am writing a script which requires a 2-dimensional array.

I need to be able to populate a matrix in zmud using x1,y1 x1,y2 etc

However, so far I've only been able to figure out how to make a single array for a variable

#VAR Xvar {x1|x2|x3}
#VAR Yvar {y1|y2|y3}

I need to make

x1y1|x2y1|x3y1
x1y2|x2y2|x3y2

anyone know how to do this in zmud?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Jul 31, 2010 2:38 am   
 
There are at least two options for you:

1)nested stringlists. Stringlists are in the form of "item1|item2|itemN". In nested stringlists, each item itself is another stringlist and is surrounded by parentheses--"(item1|item2|item3)|(item4|item5|item6)|(itemN|itemO|itemP)". Powerful, but not exactly easy to read.

2)datarecord variables. Essentially, they are stringlists where each item consists of a key=value pair. NOTE: they are NOT identical to stringlists internally, so you cannot use string functions (such as the %concat() function) to put a datarecord variable together. In the case of a 2-dimensional array, the keys would be one axis and the values would be the other. You would then use normal stringlist commands and functions to interact with the specific array element you wanted to get to.
_________________
EDIT: I didn't like my old signature
Reply with quote
surge4883@yahoo.com
Beginner


Joined: 30 Jul 2010
Posts: 19

PostPosted: Sat Jul 31, 2010 4:58 am   
 
Thanks! For what I need, I don't need it to be easy to read so I think I'm going to go with the nested stringlist.

So my next question is, if I need to get to the 15th item in the 1st slot, how would I access that value?

#VAR itemmatrix {(item1|item2...|item15|item16)|(item1|....)}
would I get it with

%item( @itemmatrix, 1, 15)

I just made that up as a guess... How do I access the specific values?
Reply with quote
charneus
Wizard


Joined: 19 Jun 2005
Posts: 1876
Location: California

PostPosted: Sat Jul 31, 2010 7:13 am   
 
Close, but you'd use %item(%item(@itemmatrix, 1), 15).

Charneus
Reply with quote
surge4883@yahoo.com
Beginner


Joined: 30 Jul 2010
Posts: 19

PostPosted: Sat Jul 31, 2010 3:57 pm   
 
thanks! I managed to almost finish what I was working on. I hit one last snag though...

How do I change values in that nested string. I am able to use loops to print the matrix to my screen and it works great, but how do I change a single value inside the matrix?
Reply with quote
surge4883@yahoo.com
Beginner


Joined: 30 Jul 2010
Posts: 19

PostPosted: Sun Aug 01, 2010 7:07 am   
 
if I have a matrix that looks like this

x x x x
x x y x
x x x x

how do I change the y to an x using a trigger?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Aug 02, 2010 2:50 am   
 
%replaceitem(%replaceitem("x",3,@mylist.2),2,@mylist)

You might need to replace @mylist.2 with %item(@mylist,2), since I forget if the former works in ZMud.

EDIT: in the future, do not spam the forums with multiple threads on the same topic in the same day (or for that matter, within the span of a day or two).
_________________
EDIT: I didn't like my old signature
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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