Scripting (ASH) question - saving outfit

darius180

Member
My current project is two scripts - one for breakfast, where I will eat, drink, etc, and put on a certain saved outfit from the prior night. The other is a nightcap script, where I overdrink, summon hearts, save my outfit, and put on rollover gear.

So my question is thus - what is the command/best way to save/recall an outfit? I havbe tried using the gCLI commands for checkpoint and outfit, and for some reason they are failing to work. Anyone have any ideas as how best to do the outfit segments of my scripts? Any feedback is greatly appreciated. Thanks.
 

Nightmist

Member
Uh given that your scripting this I assume the outfits will stay pretty much the same, so why can't you just make a custom outfit manually, and then just use those?

If its going to be a constantly changing set of gear you can save the pieces of equipment to a map, export using file_to_map and then import with map_to_file, or you can also use set_property and get_property to "save" your outfit.

Personally I would use a custom outfit and then resort to ASH map's in the event that custom outfits are not a option.
 

darius180

Member
Well, the idea would be to create a robust, versatile script - thus, i think the maps are a good way to go then. I'm not terribly sure about the specifics fo the syntax though, so if you know of any scripts using thuis functionality, I'd love to see them as examples. But I'll still try it myself and thus, thank you very much nightmist.
 
There are several samples depending on what you are looking for.

http://kolmafia.us/index.php/topic,651.0.html could be such an example, but it also does some html parsing so I'll explain a little:

Primarily the example is right at the top of the script.

PHP:
int[item] booze_consumed;
int[item] food_consumed;

void add_food_consumed(string found)
{
//the format of the string when it gets here.
//<td>[url='javascript:descitem(313835263);']extra-spicy bloody mary[/url] </td><td>1</td>
string quantstr = substring(found, last_index_of(found, "<td>") + 4, last_index_of(found, "</td>"));
string itemstr = substring(found, last_index_of(found, ";'>") + 3, last_index_of(found, "</a>"));
food_consumed[string_to_item(itemstr)] = string_to_int(quantstr);
}

void add_booze_consumed(string found)
{
//the format of the string when it gets here.
//<td>[url='javascript:descitem(313835263);']extra-spicy bloody mary[/url] </td><td>1</td>
string quantstr = substring(found, last_index_of(found, "<td>") + 4, last_index_of(found, "</td>"));
string itemstr = substring(found, last_index_of(found, ";'>") + 3, last_index_of(found, "</a>"));
booze_consumed[string_to_item(itemstr)] = string_to_int(quantstr);
}

The first 2 lines of the above declare 2 maps. The last line of each of the above functions assigns values to the map.

Reading the values is done in the main function of the script. The rest of the script simply does a lot of html parsing and calling the functions listed above to fill the maps with data.

Edit: ZOMG that makes a heck of a mess without the php tags!!!
 

darius180

Member
Thank you very much for the example! It's bebcoming clearer and clearer that my ability to deal w bthe more abstract concets (a la the more CS stuff than the KOL stuff). So I think I might be able to use that, but what I don't understand is how I would export that to a file or something....

It really is a shame that there isn't an explicit ash function for this - It seems like filling in the custom outfit box and clicking a button would be simple, but then again I don't know like, anything thorough about programming. But thank you all for your help. Hopefully all this can be used to complete my stuff.
 
void file_to_map( string file_to_load, map map_to_fill )
void map_to_file( map map_to_save, string file_to_write )


You might be able to write a function using string visit_url( string url ) if you do some homework.
 

darius180

Member
So essentially, a good idea for how to code it would be-

1)create strings, consisting of the contents of my current inventory
2)use these scripts and assemble a map . (?)
3) convert the map to file. (?)

To put on the outfit, I'd just do tha in reverse. Now, just a few questions regarding maps - should I think of them as vectors of strings ( at least that's what it looks like from this - that or arrays. Am I right?) Assuming I'm right there, would the indicies be numerical, or can I assign them a specific value? with that info, it shouldn't be too difficult to code.

Now, to do this right, I'd also need functions to get the current equip in a slot (i know that's there) and a way to take a $item[] constant to a string (I'm pretty sure I saw that). <- for my own reasoning purposes mostly, and for y'all to correct me if im wrong.

And once I get this done I suppose it's only appropriate to post my script. I should go ahead and thank whoever made that jammies.ash script - it's the basis of putting on +rollover equipment. Well, I gotta go order pizza. Thanks for all y'all's help.

edit: SO I noticed the map tutorial. uess I need to study that till i get it.
 

darius180

Member
Don't worry, i got that. I've used that to assemble every script I've made so far... Just, sometimes it really helps me to see a lot of the functions in action (in a simple kind of tutorial format).
 
[quote author=darius180 link=topic=753.msg3662#msg3662 date=1171131795]
Don't worry, i got that. I've used that to assemble every script I've made so far... Just, sometimes it really helps me to see a lot of the functions in action (in a simple kind of tutorial format).
[/quote]

That is something we are working on. If you look at the "Your Character" Page you will notice that my_class() is a link to a separate page, and the page tells what the function does, and gives a sample of it being used in a script. This part of the wiki is not finished yet, but we are working on it when we have the spare time. Eventually I hope that every function will have a code sample associated with it so that I can refer to it too. Sometimes I have to look at my old scripts to see how to use a function which I have used in the past.
 

darius180

Member
I have noticed that, and greatly appreciate it. I can donate several of my scripts when they're finished if you want - they are far from difficult to understand. Complicated stuff is byyond me... :).
 
Top