take_stash and maps issue

BDrag0n

Member
I'm writing a script to take care of my basement-diving multi for most days (except Myst, when he goes diving). The intention is to use 15 wads, of whatever type is most appropriate, and to take them from the stash if available (elsewhere in the script there's lots of pulverizing and dumping results in the stash).

However verifying the ash script gives an error "Illegal parameter #1 for function take_stash, got int, need item at line.." in the first take_stash command below. Any ideas why it's not finding an item from the map at the top?

Code:
void use_wads()
{
item [stat, int] wads;
	wads [$stat[muscle], 0] = $item[cold wad];
	wads [$stat[muscle], 1] = $item[hot wad];
	wads [$stat[mysticality], 0] = $item[spooky wad];
	wads [$stat[mysticality], 1] = $item[stench wad];
	wads [$stat[moxie], 0] = $item[sleaze wad];
	wads [$stat[none], 0] = $item[twinkly wad];

int to_use=15;
foreach key2 in wads[stat_bonus_today()]
{
        if(stash_amount(wads[stat_bonus_today(), key2])>0)
        {
         if(stash_amount(wads[stat_bonus_today(), key2])>to_use)
         {
          take_stash(to_use, wads[stat_bonus_today(), key2]);
          use(to_use, wads[stat_bonus_today(), key2]);
          to_use=0;
         }
         else{
              int taken=(stash_amount(wads[stat_bonus_today(), key2]), wads[stat_bonus_today(), key2]);
              take_stash(taken, wads[stat_bonus_today(), key2]);
              use(taken, wads[stat_bonus_today(), key2]);
              to_use=to_use-taken;
              }
         }
 }
retrieve_item(to_use, wads[stat_bonus_today(), key2]);
use(to_use, wads[stat_bonus_today(), key2]);
}
 

Veracity

Developer
Staff member
I don't get that error message. I get:

')' Expected at line 23 in file scripts/owads.ash
Script verification complete.

You have a couple syntax errors:

1) int taken = ...

The right hand side of the initialization makes no sense

2) retrieve_item( ...) references "key2" outside of the foreach. There is no key2 available there.

I simplified your function to look like this:

Code:
void use_wads()
{
        item [stat, int] wads;

        wads [$stat[muscle], 0] = $item[cold wad];
        wads [$stat[muscle], 1] = $item[hot wad];
        wads [$stat[mysticality], 0] = $item[spooky wad];
        wads [$stat[mysticality], 1] = $item[stench wad];
        wads [$stat[moxie], 0] = $item[sleaze wad];
        wads [$stat[none], 0] = $item[twinkly wad];

        int to_use=15;
        foreach key2 in wads[stat_bonus_today()]
        {
                item wad = wads[stat_bonus_today(), key2];
                int count = stash_amount( wad );
                if ( count > 0 )
                {
                        if ( count > to_use )
                                count = to_use;

                        take_stash( count, wad );
                        use( count, wad );
                        to_use = to_use - count;
                }

                if ( to_use == 0 )
                        return;
        }
}

and get no error when I verify it.
 

BDrag0n

Member
[quote author=Veracity link=topic=607.msg2879#msg2879 date=1164926363]
I don't get that error message. I get:

You have a couple syntax errors:
[/quote]
Oops, inaccurate copy/paste. /me slaps forehead

[quote author=Veracity]
I simplified your function to look like this:
[[/quote]

Thank you, Veracity
 
Top