Discard script

script now looks like this:
Code:
boolean red_out(string message) { print(message, "red"); return false; }

void main(int number, int stuff){
discard(number, stuff);
}  
{


    boolean discard(int number, item stuff)
    {
            if(is_tradeable(stuff)) return red_out("Don't discard that! It can be malled!");
            if(autosell_price(stuff) > 0) return red_out("Don't discard that! It can be autosold!");
        int amount = item_amount(stuff);
    for counter from 1 upto number
        {
            visit_url("inventory.php?action=discard&pwd=" + my_hash() + "&whichitem=" + to_int(stuff));
        }
    if(amount == 0)
        {
            print("You don't have any " + to_plural(stuff) + ".", "red");
            return false;
        }
    if(amount - number == item_amount(stuff))
        {
            print("Discarded " + number + " " + to_plural(stuff) + " successfully.", "green");
            return true;
        }
    else
        {
            print("Could only discard " + (amount - item_amount(stuff)) + " out of " + number + ".", "red");
            return false;
        }
    }
    boolean discard(item stuff)
    {
        return discard(item_amount(stuff), stuff);
    }
}


but gives off an error:
Code:
[COLOR="red"]Function 'discard( int, int )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts. (discard2.ash, line 4)[/COLOR]

useing mafia version 14.3

edit: it also does not prompt for number and item name
 
Last edited:
You added an extra {} that shouldn't be there, back when you originally set up the main. Remove the last } and the { from
right after main is declared.

And it only prompts you if the script actually runs. When it's broken, it can't run.

Ah, slight tweak as well. Main should be int, item instead. Missed that... when I was doing code work, it used ints for both of those. Change it from int number, int stuff to int number, item stuff.
 
Actually, the discard function should not be inside main at all, it should just be called from main.

Code:
boolean red_out(string message) { print(message, "red"); return false; }

discard( int number, item stuff ) {
    boolean discard(int number, item stuff)
    {
            if(is_tradeable(stuff)) return red_out("Don't discard that! It can be malled!");
            if(autosell_price(stuff) > 0) return red_out("Don't discard that! It can be autosold!");
        int amount = item_amount(stuff);
    for counter from 1 upto number
        {
            visit_url("inventory.php?action=discard&pwd=" + my_hash() + "&whichitem=" + to_int(stuff));
        }
    if(amount == 0)
        {
            print("You don't have any " + to_plural(stuff) + ".", "red");
            return false;
        }
    if(amount - number == item_amount(stuff))
        {
            print("Discarded " + number + " " + to_plural(stuff) + " successfully.", "green");
            return true;
        }
    else
        {
            print("Could only discard " + (amount - item_amount(stuff)) + " out of " + number + ".", "red");
            return false;
        }
    }
    boolean discard(item stuff)
    {
        return discard(item_amount(stuff), stuff);
    }
}

void main(int number, item stuff){
discard(number, stuff);
}

That should work, I think, assuming the internal logic is all fine.
 
EDIT: you define three discard() functions (line numbers come from Lost's post):
  • discard( int number, item stuff ) on line 3
  • boolean discard(int number, item stuff) on line 4
  • boolean discard(item stuff) on line 29

The first one lacks a return value, and has the same input as the second one.
The second one is defined inside the first one, so it won't be seen by script that import discard.ash
The third one is never called, but I guess it's meant to be called by scripts that import discard.ash. In any case, it should be defined outside of boolean discard(int number, item stuff).

Another thing: if you want Mafia to prompt how many items you want discarded, the definition of main() should be:
PHP:
void main( item stuff, int number )
instead of
PHP:
void main( int number, item stuff )
This way, when you call it from the gCLI, you simply call:
Code:
call discard.ash instant karma
This will give the script the value of stuff, and Mafia will prompt for the value of number.

You also define red_out() but don't use it everywhere. I defined a green_out() function, just to satisfy my OCD =)

Here the version with my changes:
PHP:
boolean red_out(string message) { print(message, "red"); return false; }
boolean green_out(string message) { print(message, "green"); return true; }

boolean discard(item stuff, int number)
{
	if(is_tradeable(stuff)) return red_out("Don't discard that! It can be malled!");
	if(autosell_price(stuff) > 0) return red_out("Don't discard that! It can be autosold!");
	int amount = item_amount(stuff);
	if( amount < number )
	{
		red_out("You have " + amount + " " + to_plural(stuff) + ", you can't discard " + number );
	}
	for counter from 1 upto number
	{
		visit_url("inventory.php?action=discard&whichitem=" + to_int(stuff) );
	}
	if( amount - number == item_amount(stuff) )
	{
		green_out("Discarded " + number + " " + to_plural(stuff) + " successfully." );
	}
	else
	{
		red_out("Could only discard " + (amount - item_amount(stuff)) + " out of " + number + " " + to_plural(stuff) );
	}
}
boolean discard(item stuff) { return discard(stuff, item_amount(stuff)); }

void main( item stuff, int number ){
	discard(stuff, number);
}
 
Last edited:
Back
Top