Foldables

Theraze, you Don't Get It. You did not write a function which behaves like x++ (or even ++x, although it was closer to that). You wrote a function which behaves like (x + 1). Go back and reread everything I said. Attempt to understand - and learn - and come back when you understand why your "plusplus" function is not the equivalent of a ++ operator. Until then, I've done all the teaching I care to do on this subject and have nothing further to say.
 
To go back to the original confusion... the word Banana Lord wanted wasn't function, but variable. What Winterbay attempted to do was add one to the int variable named amounts if item_amount was greater than 0. In that case, whether it was added before or after didn't matter, as it was merely incrementing the variable, not using it inline.

The problem with this is that it didn't meet the original need, which was finding out how many total foldables existed, and so using the += item_amount as Veracity suggested gives a more accurate value.

All of the rest of this fell out of Banana Lord's describing the line
amounts++;
-- which doesn't work currently but which would have been the equivalent of
amounts += 1;
if the code had interpretters for it in place -- as a function.

Edit: Also, food helps. The explanation you have made perfect sense... while "ash int number = 5; number.plusplus();" would return 6, "ash int number = 5; number.plusplus(); print(number);" would return 5, as the value of number hasn't actually been changed, unlike a proper implementation of ++.
 
Last edited:
I'm using the code Slyz posted (reposted below) and I just wanted to check how to make it get the foldable out of my DC if necessary. It's working so beautifully that I don't want to break things!

PHP:
boolean get_foldable( item goal ) 
{ 
    if ( available_amount( goal ) > 0 ) return retrieve_item( 1, goal ); 
    foreach form in get_related( goal, "fold" ) 
    { 
        if( available_amount( form ) > 0 ) 
        { 
            cli_execute("fold " + goal ); 
            return item_amount( goal ) > 0 ; 
        } 
    } 
    return false; 
}
 
After, I'd suggest, as you'd likely want to use items in inventory before you use items in your case. If you want to use foldable items first, put it just before the "return false" near the end.
 
PHP:
boolean get_foldable( item goal )
{
	if ( available_amount( goal ) > 0 ) return retrieve_item( 1, goal );
	foreach form in get_related( goal, "fold" )
	{
		if( available_amount( form ) > 0 )
		{
			cli_execute("fold " + goal );
			if ( item_amount( goal ) > 0 ) return true;
		}
	}
	// check DC
	if ( display_amount( goal ) > 0 ) return take_display( 1, goal );
	foreach form in get_related( goal, "fold" )
	{
		if( display_amount( form ) > 0 )
		{
			take_display( 1, goal );
			cli_execute("fold " + goal );
			if ( item_amount( goal ) > 0 ) return true;
		}
	}
	return item_amount( goal ) > 0 ;
}
 
Ick. I must respectfully depart from lockstep with slyz's concept. It would be far better to do it like this, both functionally and aesthetically.

PHP:
boolean get_foldable( item goal )
{  
	boolean look_get( item it )
	{
		return retrieve_item( 1, it )
			|| ( display_amount( it ) && take_display( 1, it ) );
	}
	
	if( look_get( goal ) ) return true;
	foreach form in get_related( goal, "fold" )
	{
		if( look_get( form ) )
		{
			cli_execute("fold " + goal );
			return item_amount( goal ) > 0 ;
		}
	}
	return false;
}
 
Last edited:
I thought it was better to check for all the forms that might be in your inventory before resorting to take items out of your DC.

EDIT:
PHP:
boolean get_foldable( item goal )
{
	boolean look_get( item it, boolean DC )
	{
		if ( DC ) return ( display_amount( it ) > 0 && take_display( 1, it ) );
		return ( available_amount( it ) > 0 && retrieve_item( 1, it ) );
	}
	foreach DC in $booleans[ false, true ]
	{
		if ( look_get( goal, DC ) ) return true;
		foreach form in get_related( goal, "fold" )
		{
			if( look_get( form, DC ) )
			{
				cli_execute("fold " + goal );
				if ( item_amount( goal ) > 0 ) return true;
			}
		}
	}
	return item_amount( goal ) > 0 ;
}
 
Last edited:
I thought it was better to check for all the forms that might be in your inventory before resorting to take items out of your DC.
I would agree with that methodology (though Bale's code is prettier than what you posted earlier. Oh isn't there some way I can make you BOTH happy?? :P). Could you explain the functional difference between the code you posted most recently and the code you posted earlier?
 
They do the same thing (I think) but the second is much prettier :)
It tries to satisfy with yoru inventory and if that doesn't work tries with your display case instead.
 
Functionally, there's no difference. I just took Bale's more elegant code and made it do what I wanted ^^
 
Back
Top