data files

martialis

New member
help with javascript functions or mall cleverness

whenever I say store_amount, it seems to be asking the server. this is bad. is it supposed to do that?
how do I do +=?

how do I do new string(char, int)?
some of the prices are fucked up, so I appreciate any advice on that
 
Last edited:

DerDrongo

Member
in ash script you can use the file_to_map and map_to_file, both commands take a string (the filename) and a map (an array/hash (perl's name for it))
a very basic map is...
Code:
//define the map
string [string] basic_map;
//fill the map
basic_map["one"] = "1";
basic_map["two"] = "2";
// output map
map_to_file(basic_map, "out_basic.txt");
that will make the text file "out_basic.txt" with...
one 1
two 2
(the data is separated by tabs)

a more complex map uses records such as...
Code:
//define the record/map
record {
	int price;
	int amount;
} [item] adv_map;
//fill the map
adv_map[$item[heavy D]].price = mall_price($item[heavy D]);
adv_map[$item[heavy D]].price = item_amount($item[heavy D]);
// write the file
map_to_file(adv_map, "out_adv.txt");
that will make the text file "out_adv.txt" with...
heavy D 0 0
with the first 0 being the price and second 0 being the amount

reading in the file "out_adv.txt" is just as easy...
Code:
//define the record/map
record {
	int price;
	int amount;
} [item] adv_map;
//fill the map
file_to_map("out_adv.txt", adv_map);
and now you can access all the data from the file

hope that helps you get started
 

martialis

New member
thanks

whenever I say store_amount, it seems to be asking the server. this is bad. is it supposed to do that?
how do I do +=?
 
Last edited:

martialis

New member
well, here's what I stole from Bale. does anyone have any comments?

how do I do new string(char, int)?
some of the prices are fucked up, so I appreciate any advice on that

you have to rename price_list.txt.ash to price_list.txt because this forum is broken, apparently. price_list.ash is a mallbot which you shouldn't run, at all, really, but especially not without reading it
 

Attachments

  • price_gun.ash
    1.5 KB · Views: 71
  • price_list.txt.ash
    84.9 KB · Views: 69
  • price_list.ash
    2.2 KB · Views: 69

dangerpin

Member
And by mallbot you mean it is a script that takes items out of inventory and puts them in the mall at a specified price, right? It looks like that is what the script does.

When we talk about mallbots we often mean a bot set up to monitor the mall and buy items at a certain price or less. We don't allow posting of those types of scripts.
 

DerDrongo

Member
whenever I say store_amount, it seems to be asking the server. this is bad. is it supposed to do that?
how do I do +=?
mall_price will search the mall for a price (contacting the server), it should only do so once per session per item

martialis said:
how do I do new string(char, int)?
looking at your code it seams that the item is your unique key (for looking up data in the maps) so you would use
Code:
record {
int number1;
string string1;
} [string] map_name;
martialis said:
some of the prices are fucked up
kolmafia sends the exact name (including quotes/special characters) to the mall search, kol itself doesnt support special characters being used in searches so any errors you see are likely the result of that

while this script isnt a mallbot (no automatic buying of low-than-average priced items) it does request the prices of almost three thousand items which seams a lot more than should be needed, i would recommend you try and keep your price request to under 50 a day to make sure your accounts dont get locked
 

Veracity

Developer
Staff member
whenever I say store_amount, it seems to be asking the server. this is bad. is it supposed to do that?
store_amount tells you how many of an item you have in your store. That's not a constant unchanging amount, unlike closet, storage, display case, etc., since people can buy an item from you between the last time you checked and this time.

Given that, how would propose that store_amount work WITHOUT going to the server?

how do I do +=?
Transform it in the obvious way. Instead of "a += b", write "a = a + b".
 

martialis

New member
well, can I get the potential earnings for the store, or the list of items in the store with 1 query?

which items can mafia not search for properly? genalen bottles, is that it? filet of tangy gnat works fine for me.

oh, and how do I get my_hangksmeat()?
 
Last edited:

mredge73

Member
Quick question:
Is there a way to record the cli output to a map file so the output can be used in a script?
This would be useful to get feedback from the cli for functions like cli_execute("expensive ") and feedback on item creation to see if the item was actually created or auto sell to see if it was actually auto sold.

I haven't tried to create my own maps yet so I don't know if this is something that they can do.
 

jasonharper

Developer
Quick question:
Is there a way to record the cli output to a map file so the output can be used in a script?
No, because that would allow scripts to do unrestricted Mall searches.

To duplicate the functionality of "expensive", put all the desired items in an array, and sort it by -mall_price(value).
 

mredge73

Member
I am glad you mentioned that:
I have seen a sort function implemented on one of bale's scripts. Where can I find documentation on how this works and the options available. I ran a search for "sort" in ashref commands, cli_execute commands, these forums, and on the main mafia page. Is this something that is default for arrays in the java language? I am new to java, my limited experience is in C, C++, asm, latter logic, and microchip pic code and if I need to sort objects I have to write a function to do so.
 
Top