i suck at ash maps

razorboy

Member
I'm working on a script that checks how many tiny plastic drinks I can make, but I've never used maps before, and I seem to be doing it wrong.

Code:
string [int] map1;
map1[1] = "sangria del diablo";
map1[2] = "cherry bomb";
map1[3] = "bodyslam";
map1[4] = "grogtini";
map1[5] = "dirty martini";
map1[6] = "vesper";

for i from 1 to 6
{
print("Total possible " +map1[i]+ " is: " + to_string(available_amount(map1[i]) + creatable_amount(map1[i])));
}

This gives me a wierd error:
Function 'available_amount( string )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts. (whatsdrinkable.ash, line 12)

I'm using the "total possible" example from the wiki, but I think there's some issues with the type. The example uses item afue = $item[scroll of ancient forbidden unspeakable evil]; but I tried item foo = $item[map1]; but that didn't work at all. The error was "Cannot store string in foo of type item (whatsdrinkable.ash, line 12)".

What am I doing wrong here?
 
Last edited:
You're map is a map of strings and your trying to use functions that require items.

Either change your map so the values are items:

Code:
item[int] map1
map1[1] = $item[sangria del diablo];

or convert the strings to items in your for loop:
Code:
print("Total possible " +map1[i]+ " is: " + (available_amount(map1[i].to_item()) + creatable_amount(map1[i].to_item())));
 
You don't necessarily need a map. You could also do something like this:
Code:
foreach drink in $items[sangria del diablo, cherry bomb, bodyslam, grogtini, dirty martini, vesper]
    print("Total possible " + drink + " is: " + (available_amount(drink) + creatable_amount(drink)));
 

slyz

Developer
Apparently your problem wasn't with maps but with available_amount() and creatable_amount(). Maps aren't that hard!

I would love to test this, but it would need many donations of TPSs, just to test it *really* thoroughly... (I don't think available_amount() + creatable_amount() > 1 is true for many people in this case, let alone for more than one of those drinks :D)
 

Grotfang

Developer
Maps can be frustrating if you haven't encountered similar structures before. However, they are well worth dealing with (even if your current script doesn't require them). For a run-through of how to use them, Veracity has a nice little guide that you can find here. Alternatively, in the discussion section of that page there is an additional guide that takes you through a guide of using records and multiple keys in baby-steps. You can find that here.

Hope that helps!
 
Last edited:

razorboy

Member
You don't necessarily need a map. You could also do something like this:
Code:
foreach drink in $items[sangria del diablo, cherry bomb, bodyslam, grogtini, dirty martini, vesper]
    print("Total possible " + drink + " is: " + (available_amount(drink) + creatable_amount(drink)));

I just wanted to reply and said I'd modified this into a one-line script I can just CLI with the "ash" command. (I wanted a quicky "available_amount").

Code:
ash print("Total limes are: " + (available_amount($item[lime])));

This is totally awesome and saves me from having to root around in my inventory when all I need is a quick number.

Thanks again guys!
 

heeheehee

Developer
Staff member
Also, an alias might help you here --
Code:
alias tpsdrinks => ash foreach drink in $items[sangria del diablo, cherry bomb, bodyslam, grogtini, dirty martini, vesper] print("Total possible " + drink + " is: " + (available_amount(drink) + creatable_amount(drink)));

Then, whenever you type "tpsdrinks" into the CLI, it'll tell you how many of each of 'em you can make.
 

razorboy

Member
Edit: I looked up alias in the wiki, and it explains a bit... but where are these commands stored? For backup purposes.
 
Last edited:
Top