# ADV-PROG Re: Defining New Error Codes? [SERVER]

ThwartedEfforts (abakun@rci.ripco.com)
Wed, 23 Aug 1995 12:54:00 PDT

- Messages sorted by:[ date ][ thread ][ subject ][ author ]

    >I'd like to know if it's possible to define new error codes; for instance,
    >a MOO with monetary units might need an 'E_INSFUND' (insufficient funds)
    >error.
    >
    >This should be defined as an error so that it evaluates false.  Is there
    >any way to do this short of a server hack?  If not ... how tough of a
    >server hack is it? :)

    Here's a(n extreme) work around and some will think it's a total hack:

    @prop #0.E_INSFUND #-5

       (#-1, #-2, #-3 are already taken, and on E_MOO, I already have #-4
        defined as $this for the parser.  You mainly just want to use a
        negative object number here that is less than #-3 and not used by
        anything else (nothing in a standard lambdacore uses anything less
        than #-3))

    Object numbers are false.  You can then pass this value around all you want.
     Unfortunately, it will return OBJ in a typeof(), so you can't necessarily
     compare it to ERR to determine if it's an error.

    $player:check_funds
    if (player.funds =< 0)
      return $E_INSFUND;
    else
      return this.funds;
    endif

    $player:buy_stuff
    if (player:check_funds() == $E_INSFUND)   OR   if (!player:check_funds())
      player:tell("Get a job!");                     player:tell("Get a job!");
    else                                           else
      player:buy_it();                               player:buy_it();
    endif                                          endif

    Anyway, it will be false, which will serve the purpose.  This mainly makes the
     code easier to read.  Point to remember that core refs cost a tick, you might
     want to take that into account in code you want to be as fast as possible
     (that is just something to keep in mind, but it's hardly worth sweating over
     for most cases).

    Also, you might also want to do something like this:

    $string_utils:tostr
    if (args[1] == $E_INSFUND)
      return "Insufficient funds.";
    else
     <... rest of code ...>

    To get good output for to string'ing.  You'll have to pass through
     $string_utils, but a small price to pay.  A change to $string_utils:print
     would also come in handy.  On E_MOO, we are keeping track of core refs, so
     things like:

         ;$E_INSFUND
         => $E_INSFUND

     will come up instead of

         ;$E_INSFUND
         => #-5

    Anyone for frobs? (thereby allowing you to overload typeof() and account for
     this) :) :) :)  But let's not get into that.  (Check the archives).

    It's probally not worth it for a server mod.

      ______                              __
        /   /  Andy Bakun     _/_      / /  `  /)  /)       _/_
     --/   /_  , , , __.  __  /  _  __/ /--   //  //  __,_  /  _
    (_/   / /_(_(_/_(_/|_/ (_<__</_(_/ (___, //__//__(_) (_<__/_)_
      How much head could a bonehead bone   />  />
        if a bonehead could bone head?     //  //
      http://shrike.depaul.edu/~abakun/   </  </