Author Topic: Possible bug in meal.c  (Read 1223 times)

Offline Lash

  • Acquaintance
  • *
  • Posts: 42
    • View Profile
Possible bug in meal.c
« on: December 13, 2014, 09:18:17 AM »
In meal.c there is this variable:
Code: [Select]
function MealAction;
defined in:

Code: [Select]
int SetMealAction(function f){
    MealAction = f;

The above function is not referenced in the /docs folder that I could find. No biggie. But, the function is only evaluated in 'mixed eventEat(object who)' in meal.c and not in 'mixed eventDrink(object who)'. Therefore, only meals that are eaten and not drunk get the benefit of the call to function if

Code: [Select]
SetMealAction((: foo :));
is set in a meal that is to be drunk defined by

Code: [Select]

The following code must be added to the 'mixed eventDrink(object who)' portion of code in meal.c in order for drink meal types to make use of SetMealAction()

Code: [Select]
if( (x = functionp(MealAction)) && !(x & FP_OWNER_DESTED) ){
        evaluate(MealAction, who);

The only other option discussed for making calls to a function was to use SetMealMessages() which has a check for a function pointer in the first value used in this function. SetMealAction() is useful for strictly added a call to your particular function added to the meal.

The below code is a an example for using SetMealAction() in a drink that has a one shot deal for curing paralysis in the player.
Code: [Select]
#include <lib.h>
#include <meal_types.h>

inherit LIB_MEAL;

void remove_paralysis();

static void create() {
    SetId( ({ "water","pure water" }) );
    SetShort("a vial of crystal clear pure water");
    SetLong("It is glowing!");
    SetMealAction((: remove_paralysis :));
    //SetMealMessages((: remove_paralysis , "drink":));

void init(){

void remove_paralysis(){
    object ob = this_player();
    if(ob && ob->GetParalyzed()) ob->SetParalyzed(0);   
    tell_player(ob, "\nThe call to function worked!\n");