Over-ridden functions

from time to time I have found myself over-riding some of kolmafia's built-in functions with my own. Several times though I have wanted to call the over-ridden function within the function I wrote. This makes me wish there was command "overridden" which when kolmafia encounters it kolmafia would look for another function with the same name, and call it passing the same parameters or if parameters are given pass them.

examples:

refuse to buy a tiny plastic sword, but buy anything else.
if I want a spring buy a meat engine and untinker it
Code:
boolean buy( int quant, item tobuy )
  {
  if(tobuy == $item[tiny plastic sword])
    {
    //print an error message
    return false
    }
  return overridden;
  }

boolean buy(int quant, item tobuy )
  {
  if(tobuy == $item[spring] && !in_muscle_sign())
    {
    int onhand = item_amount(tobuy);
    overridden(quant, $item[meat engine]);
    cli_execute("untinker " + quant + " " + $item[meat engine]);
    cli_execute("untinker " + quant + " " + $item[cog and sprocket assembly]);
    cli_execute("untinker " + quant + " " + $item[sprocket assembly]);
    cli_execute("untinker " + quant + " " + $item[full meat tank]);
    sell_item(quant, $item[meat stack]);
    return ((onhand + quant) = item_amount(tobuy));
    }
  return overridden;
  }

There may be a better name for the command, and there definitely is far better uses for it than the ridiculous spring example I have shown.

effectively the TPS blocking buy function would over-ride kolmafia's built in buy function, and the spring one would over-ride the TPS blocking one. when the command "buy(1, $item[asshat])" is encountered kolmafia would use the spring version first, then that command would call the TPS blocking version, then the TPS blocking version would resort to the built in kolmafia function which has a way to handle all items which can be bought, but we may not like how it's done.

Keep in mind that though the example appears to be an effort to squeeze a couple of extra meat out of the game, it actually is just a quickly written example.
 

Veracity

Developer
Staff member
[quote author=efilnikufecin link=topic=796.msg3840#msg3840 date=1172572478]
from time to time I have found myself over-riding some of kolmafia's built-in functions with my own. Several times though I have wanted to call the over-ridden function within the function I wrote. This makes me wish there was command "overridden" which when kolmafia encounters it kolmafia would look for another function with the same name, and call it passing the same parameters or if parameters are given pass them.[/quote]

If we were to do this, I'd prefer something like "return super( ... )", which is how Java, e.g., calls the "superclass" version of the method you're within.
 
[quote author=Veracity link=topic=796.msg3842#msg3842 date=1172590944]


If we were to do this, I'd prefer something like "return super( ... )", which is how Java, e.g., calls the "superclass" version of the method you're within.
[/quote]

3 cheers for shorter more common names! That would be great if not too hard to implement! BTW I didn't know until now what super did in Java but wondered about it. Thanks!
 
Top