item lists from text files?

razorboy

Member
I was just wondering if ash has the ability to open text files and pull input from them.

I was thinking of writing an inventory manipulation script, but I don't really want a gigantic list of items in it... plus I would like to reuse the item list.

Is this possible?
 
(Why can't we just use arrays?)

Those are effectively (same interface) just integer-indexed maps (with optimized implementation).
Unless you want static arrays, where you have to know how many items you are storing even *before* you store the firts one.
 
You want arrays? ASH has them. An array can be considered to be a map that has integer keys numbered from 0 to <n>.

Code:
string [int] MyMap;
string [6] MyArray;

MyMap[5] = "this works";
MyMap[100] = "this too";

MyArray[5] = "this works too";

foreach i, s in MyMap
  print( "MyMap[" + i + "] = " + s );

foreach i, s in MyArray
  print( "MyArray[" + i + "] = " + s );

int index = 100;

MyArray[index] = "this generates a runtime error";
does this:

> ma.ash

MyMap[5] = this works
MyMap[100] = this too
MyArray[0] =
MyArray[1] =
MyArray[2] =
MyArray[3] =
MyArray[4] =
MyArray[5] = this works too
Array index out of bounds (ma.ash, line 17)
 
Awesome! Something I understand! Thanks Veracity!

Back to the file thing:
If someone has admin access to the wiki, they may want to add to the "file_to_map()" entry that the items in the file need to be tab-separated (at least on Windows). It's not readily apparent in the example, and I tried to use spaces... which didn't work.
 
That information should definitely be added.

If someone has admin access to the wiki, they may want to add to the "file_to_map()" entry that the items in the file need to be tab-separated (at least on Windows). It's not readily apparent in the example, and I tried to use spaces... which didn't work.

Admin access is not necessary. Anyone can add to the wiki. (It's a wiki!) Though it would be nice if you created an account before editing the wiki, just so we know it's you.

Edit: Added info, but perhaps there is a better way of stating it.
 
Last edited:
You want arrays? ASH has them. An array can be considered to be a map that has integer keys numbered from 0 to <n>.

Code:
string [6] MyArray;

Hmm, never knew that syntax before. That opens a slew of questions:
  1. Do they work with floating-point numbers or strings? (i. e. string [ "stm" ] a_map; string [ 12.5 ] some_map; )
  2. Do they work multidimensionally? (i. e. string [5, 5] multi_dim_array; )
  3. Are they internally treated differently from normal maps? If so, I feel it should be discussed as a separate data type in the wiki.
 
1. Arrays in this context can only be indexed by integer.
2. Yes, try it out yourself!
Code:
ash string [5, 5] multi_dim_array; foreach i,m in multi_dim_array print(i+":"+m)
3. I have no idea, although I do recall JH mentioning that maps, arrays, and datatype constants are the three implementations of aggregates in KoLmafia. Probably a yes?
 
Back
Top