A Tutorial On Maps

reverkiler

New member
Hey, I've been lurking for a little while, but I have no idea how to use maps. I looked on the wiki and didn't see anything. Can anyone point me to a good tutorial other than reading a bunch of other people's code?\

Edit:
Liar, Liar, Pants on fire.
 
Last edited:

reverkiler

New member
I have a couple of other questions.
Whats the best way to write and retrieve from a file?
Also, is there a file with all of the safe moxie values for every location somewhere?
 

heeheehee

Developer
Staff member
file_to_map and map_to_file are your best bets. And monsters.txt (in your data folder) has all monster stats, in alphabetical order.
 

xKiv

Active member
And combats.txt lists monsters for each adventure area.

If you don't have combats.txt or monsters.txt in your data/ directory (which is likely), look for them in the data/ directory inside kolmafia's .jar file (probably easiest way: rename/copy it to a .zip file).
 

reverkiler

New member
I have one more question.
Is there a way for me to call a function whose name I only know at runtime?
like... how they do sort?
 

Spiny

Member
If you're looking for something with safe adventuring, you may want to look into Zarqon's canadv.ash script.
 

xKiv

Active member
Or type "update data" into the graphical CLI in Mafia.

Only if you put it in your loginScript. Otherwise, you will be left confused when your data files stay hopelessly out of date even though you have the latest build ...

(Or you could move them to some other location afterwards; or just use SVN to download the latest sources)

I have one more question.
Is there a way for me to call a function whose name I only know at runtime?
like... how they do sort?

Worst case, something like (off the side of my head - not running mafia to check right now)

string command="print(1)";
cli_execute("ash " + command);
 
Last edited:

heeheehee

Developer
Staff member
Only if you put it in your loginScript. Otherwise, you will be left confused when your data files stay hopelessly out of date even though you have the latest build ...

Ehh? It works for me if I just type it in manually. I really don't think there's a difference between manually typing something in and putting it in the loginScript (except, of course, one executes every time you log in).
 

lostcalpolydude

Developer
Staff member
Ehh? It works for me if I just type it in manually. I really don't think there's a difference between manually typing something in and putting it in the loginScript (except, of course, one executes every time you log in).

If it isn't done automatically, you can forget to do it, and then mafia uses out of date files that can create undesired results.
 

heeheehee

Developer
Staff member
If it isn't done automatically, you can forget to do it, and then mafia uses out of date files that can create undesired results.

Right on. I guess that'd be less loading on the servers for the individual to do that than for scripts to do that every time they're executed.
 

xKiv

Active member
Right on. I guess that'd be less loading on the servers for the individual to do that than for scripts to do that every time they're executed.

It's even less load for the servers to *never* do it.
Coincidentaly, less load for the individual.
 

Grotfang

Developer
Not immediately related, but given the title is "A Tutorial on Maps" I'm hoping someone can help me :)

Is it possible to make an array that uses strings as the key to be order not by alphabetical order, but by order in which they are entered?

For example:

Code:
string [string] a;
a["one"] = "1";
a["two"] = "2";
a["three"] = "3";
map_to_file( a , "a.txt" );

Produces:

Code:
one	1
three	3
two	2

When I would rather it were in order. Does that make sense? If it's not possible, that's fine (this is clearly not a bug), but if anyone knows a technique to change it, that would be great.

Cheers
 

Grotfang

Developer
I'm not sure sort is exactly what I'm looking for, here. You see, I want the keys to change position too. Anyhoos, I will work on this, it might be possible to have two maps, one where the contents (sorted) become the keys for the final (used) map.

Cheers
 

slyz

Developer
Why would the order matter ? A map is just a bunch of unrelated relations, isn't it ? The only thing the relations in a map have in common is the type of values they are relating.

Quoting jasonharper in the thread mredge73 linked:

Basically, 'sort' is only useful in cases where your data exists entirely in the values of the map; the keys can have no meaning beyond simply being distinct.

Changing the 'position' of the keys along with the values (i.e., the order in which the map is entered ?) won't change how the map is printed to the file.
 

Grotfang

Developer
Sometimes the relations are important. This is what prompted my question and also what made me say "I want the keys to change position too". Bear in mind that the keys as well as the values are printed to the file. Therefore, if the position of the keys stays the same while the position of the values change, it will (and indeed, does) change the way the map is printed to the file.

I do concede that mine is a minority interest. I am not complaining about how the current system works - it is the sensible system. What I am doing is trying to find a way to work with it to produce the result I want.
 

Bale

Minion
mafia is not really designed to produce text file output. If this is your interest, I'd suggest you look into the mirror command to produce the output you want. It's the only way to make sure that a file contains your desired output in the order you want it in.
 

slyz

Developer
Oh, I wasn't talking about switching around keys without their values: what's important is exactly that, the links between keys and values. Those links don't have any relationship between them, though, and their order has nothing to do with the map they are in.

I meant to say that you can't have a map with those keys and their associated values that will be printed any other way in a file (using map_to_file). Was that the result you were looking for ?
 
Top