Random Questions

Thanks tomasb. I’ll see what I’m doing wrong there. Maybe adding a new directory is what was causing the problem.

I’m having another instantiation issue with a class object. I’m setting isEquivalent, but it still seems to add a new one for each one I take. Also there’s a disambiguation issue between the wild sorrel main object, and the ones held in inventory.

[code]trailSideSorrel : Food
name = ‘sorrel’
vocabWords = ‘sorrel*sorrels’
desc = “Spinach greens about a foot high. Some leaves are growing a little more gnarled than
others, while a couple are riddled with holes.”
location = brownieForestAroundHouse
disambigName = ‘wild sorrel’
dobjFor(Take)
{

    action()
    {
        
        sorrel = new Food('sorrel', 'sorrel*sorrels');
        sorrel.set_desc('Sorrel herb. Commonly called spinach.');
        sorrel.disambigName = 'owned sorrel';
        sorrel.uses = 1;
        sorrel.nutrition = 12;
        sorrel.shelfLife = 75;
        sorrel.canRot = true;
        sorrel.hasEffect = nil;
        sorrel.isFresh = true;    
        sorrel.isPlural = true;
        sorrel.isEquivalent = true;
        sorrel.vocabLikelihood = 10;
        sorrel.location = gActor.getOutermostRoom();
        sorrel.moveInto(gActor);
        "<<me.name>> takes some of the fresh sorrel leaves.";
        
    }
    
}

;[/code]

food class

modify Food
    name = ''
    vocabWords = ''
    desc = ""
    uses = 1
    nutrition = 1
    shelfLife = 75
    isEquivalent = true
    canRot = true
    hasEffect = nil
    isDry = nil
    isBurnt = nil
    isFresh = nil
    isSalty = nil
    isSour = nil
    isSweet = nil
    isSpicy = nil
    isSavery = nil
    isBitter = nil
    isRotten = nil
    
    construct(nameSet, vocabSet)
    {
        name = nameSet;
        vocabWords = vocabSet;
       
        initializeVocabWith(vocabWords);
        
    }
    
    set_desc(descSet)
    {
       
        desc = descSet;
        
    }
    
dobjFor(Eat)
    {
        
        action()
        {
                 
                if(gActor.hungerBar + 1 >= gActor.maxHunger)
                {
                
                        // used
                 
                    if(self.canRot)
                    {
                        self.uses -= 1;
                    }
        
                    if(self.uses <= -1)
                    {
                        self.uses = -1;
                    }
        
            
                if(gActor == me)
                {
                        
                        if(gDobj.isPlural)
                        {
                            
                            message =  '<<me.name>> places some of {the dobj/he} into 
                                    <<me.return_pronoun('his/her', me.gender)>> mouth. ';
                       
                        }else{
                            
                             message =  '<<me.name>> places {the dobj/he} into 
                                    <<me.return_pronoun('his/her', me.gender)>> mouth. ';
                            
                        }
                        
                        if(isFresh)
                        {
                            
                            message += '<<one of>>Fresh and delicious. 
                                        <<or>> It tastes good. 
                                       <<or>> It\'s great. 
                                        <<or>> Couldn\'t be fresher. ';
                                
                        }
                        
                      if(isDry)
                        {
                           
                            message += ' <<one of>>it\'s a bit dry and textury to chew on.<<or>> It\'s so dry,
                               it\'s hard to chew.<<end>>';
                            
                            me.thirstBar -=1;
                            
                            if(me.thirstBar < 0)
                            {
                                me.thirstBar = 0 ;
                            }
                        
                        }
                    
                        if(isSalty)
                        {
                            
                            message += 'It\'s quite salty to the tongue.';
                            
                            me.thirstBar -= 2;
                            
                            if(me.thirstBar < 0)
                            {
                                me.thirstBar = 0 ;
                            }
                        
                        }
                    
                       if(isBurnt)
                        {
                            message += '<<one of>>This is like eating charcoal.<<or>> This is worst than chewing
                                on a burn, fresh from a campfire.';
                        }
                    
                        if(isSpicy)
                        {
                        
                            message += '<<one of>>{The dobj/he} is spicy, causing the taste buds to dance.<<or>>
                                    It\'s so spicy it makes the mouth a little dry.<<end>>';
                            
                            me.thirstBar -=1;
                            
                            if(me.thirstBar < 0)
                            {
                                me.thirstBar = 0 ;
                            }
                        
                        }
                    
                        if(isSour)
                        {
                        
                            message += '<<one of>> Bitterness causes <<me.return_pronoun('his/her', me.gender)>> lips
                                to pucker.';
                        
                        }
                    
                        if(isSovory)
                        {
                        
                            message += 'It\'s a bit savory on the palate.';
                        
                        }
                    
                        if(isRotten)
                        {

                            message += '{the dobj/he} tastes putrid. It\'s rotten!';
                            
                        }       
                    
                    "\n\b";
                        
                        // handle eating of non-rotten food
                    if(!self.isRotten)
                    {
                          
                        me.hungerBar += self.nutrition;
                      "<<message>>\n";
                        "\t Hunger +<<self.nutrition>>\n";
                    
                    }else{
                
                            me.hungerBar -= self.nutrition;
                            "<<message>>\n";
                            "\t Hunger -<<self.nutrition>>\n";
                    
                            // character also looses around 10% of max life
                            amount = new BigNumber(me.hpMax * 0.25, 2);
                            amount = amount.getCeil();
                            realAmount = new BigNumber(rand(amount) + (amount + (amount/2)), 2);
                            realAmount = realAmount.getCeil();
                            me.hp -= realAmount;
                            "\t Hp -<<realAmount>>\n";
                
                            if(me.hp < 0)
                            {
                                me.hp = 0;
                            }
                       
                        // end eating rotten food
                      }
                    if(me.hungerBar > me.maxHunger)
                    {
                        
                        me.hungerBar += me.maxHunger;
                        
                    }
                        
                    // BUG: add effect code for food.
                    // hasEffect
                      // apply the effect in the food.
                    
                    // end if gActor == me (handle eat for npx)
                }else{
                     
                    // BUG : handle rotten food for NPC
                    if(gDobj.isPlural)
                        {
                            
                            message =  '<<me.name>> places some of {the dobj/he} into 
                                    <<me.return_pronoun('his/her', me.gender)>> mouth. ';
                       
                        }else{
                            
                             message =  '<<me.name>> places {the dobj/he} into 
                                    <<me.return_pronoun('his/her', me.gender)>> mouth. ';
                            
                        }
            
                        "\n";
                        gActor.hungerBar += self.nutrition;
                        "\t Hunger +<<self.nutrition>> (<<gActor.name>>)";
                        
                    if(gActor.hungerBar > gActor.maxHunger)
                        {
                            
                            gActor.hungerBar += gActor.maxHunger;
                            
                        }
                        
                    // end if gActor == npc
                }
            
                if(gDobj.uses <= 0)
                {
            
                    gDobj.moveInto(nil);
                    gDobj.location = nil;
                    
                }
        
                    
                }else{
                    
                    "<<gActor.name>> isn't hungry enough to eat {the dobj/he}.";
                    
                }
                
            // end action
        }
        
      // end dobjFor eat  
    }
        // remove food if eaten
   afterAction()
    {
        
        if(self.uses <= 0)
           {
            
        
                self.moveInto(nil);         
           
           }
  
        food_handler();
    
    }
    
    
    // food_handler for rotting food
    // BUG : Finish food handler
    food_handler()
    {
        
        self.shelfLife -= 1;
        switch(self.shelfLife)
        {
           
            case 25:
                "<<one of>>Something is beginning to smell a little funny. 
                <<or>> Something smells a bit off.
                <<or>> Something doesn't smell right.";
            break;
            case 0:
                "<<one of>>Something smells rotten. 
                <<or>> Something smells putrid.
                <<or>> A putrid smell wafts up from somewhere.";
                self.isRotten = true;
                self.name = 'rotten ' + self.name;
                self.vocabWords = 'rotten <<self.name>>';
                isFresh = nil;
                isSalty = nil;
                isSour = nil;
                isSweet = nil;
                isSpicy = nil;
                isSavery = nil;
                isBitter = nil;
            break;
        
        }
    }
    
;

How many sorrels you want in your game?

If this is the first time you have split your source into separate files, be aware of a trap you can fall into. If you do not include the right #include directives at the top of every source file, you will get weird compiler errors that you don’t expect.

Typically your primary .t file has the following near the top. If so, you generally want to put the same into your other .t files.
#charset “us-ascii”
#include <adv3.h>
#include <en_us.h>

I can’t tell if this is actually your problem, but might be worth a look.

Greg

Thanks guys, I’ll check out the files again. I’m not sure if I but the charset at the top or not, the other two were included.

I’d like the character to be able to take as many sorrel as they want, and have them equivalent, saying you have xsorrel. Also if I wanted a limited number, as in they picked all the wild sorrel there, what would be the way?

I really can’t see what I did wrong. The vocab should be initialized.

So what about:

[code]#charset “utf-8”

#include <adv3.h>
#include <en_us.h>

versionInfo: GameID;

gameMain: GameMainDef
initialPlayerChar = me
;

Room ‘room’ ‘room’
"Room. "
;

  • me: Actor;

class Sorrel: Food ‘sorrel herb/sorrel/spinach*sorrels herbs’ ‘sorrel’
"Sorrel herb. Commonly called spinach. "

isPlural = true
pluralName = 'sorrels'
isEquivalent = true

uses = 1
nutrition = 12
shelfLife = 75
canRot = true
hasEffect = nil
isFresh = true

;

  • Surface ‘bed of plants’ ‘bed of plants’
    ;

++ trailSideSorrel: Sorrel ‘wild -’ ‘sorrel’
"Spinach greens about a foot high. Some leaves are growing a little more
gnarled than others, while a couple are riddled with holes. "

dobjFor(Take)
{
    action()
    {
        local sorrel = new Sorrel;
        sorrel.moveInto(gActor);

        "{You/he} takes some of the fresh sorrel leaves. ";
    }
}

;[/code]

Which would lead to the following transcript, just note I’m not a native English speaker so some grammar may need to polish. But you should get the idea:

Thanks Tomasb. I’m curious, what am I doing wrong? What exactly is the bug? Why couldn’t I instantiate sorrel from my modified Food class, since I added the constructor? I’m not sure why that wouldn’t work without a new class.

I appreciate the code, will use if need be, but not sure why the new sorrel class is needed :stuck_out_tongue:

I’m still getting the same bug. I’m part way between your code, and my own. I had to add name and vocabwords through my food class constructor. I’m still getting the “no isEquivalent effect” though.

sorrel item in the room.


trailSideSorrel : Sorrel
    name = 'sorrel'
    vocabWords = 'sorrel*sorrels'
    desc = "Spinach greens about a foot high. Some leaves are growing a little more gnarled than 
        others. Many of the leaves are lush green, while others are riddled with tiny sholes."
    location = brownieForestAroundHouse
    disambigName = 'wild sorrel'
    isEquivalent = true
    dobjFor(Take)
    {
        
        action()
        {
            
            sorrelFood = new Sorrel('sorrel', 'sorrel*sorrels');
            sorrelFood.location = gActor.getOutermostRoom();
            sorrelFood.moveInto(gActor);
            "<<gActor.name>> takes some of the fresh sorrel leaves.";
            
        }
        
    }
            
;

Sorrel class

class Sorrel : Food disambigName = 'sorrel in inventory' desc = 'Sorrel greens. Commonly called spinach.' uses = 1 nutrition = 12 shelfLife = 75 canRot = true hasEffect = nil isFresh = true isPlural = true isEquivalent = true vocabLikelihood = 10 ;

food class

[code]modify Food
name = ‘’
vocabWords = ‘’
desc = “”
uses = 1
nutrition = 1
shelfLife = 75
isEquivalent = true
canRot = true
hasEffect = nil
isDry = nil
isBurnt = nil
isFresh = nil
isSalty = nil
isSour = nil
isSweet = nil
isSpicy = nil
isSavery = nil
isBitter = nil
isRotten = nil

construct(nameSet, vocabSet)
{
    name = nameSet;
    vocabWords = vocabSet;
   
    initializeVocabWith(vocabWords);
    
}

set_desc(descSet)
{
   
    desc = descSet;
    
}

dobjFor(Eat)
{

    action()
    {
             
            if(gActor.hungerBar + 1 >= gActor.maxHunger)
            {
            
                    // used
             
                if(self.canRot)
                {
                    self.uses -= 1;
                }
    
                if(self.uses <= -1)
                {
                    self.uses = -1;
                }
    
        
            if(gActor == me)
            {
                    
                    if(gDobj.isPlural)
                    {
                        
                        message =  '<<me.name>> places some of {the dobj/he} into 
                                <<me.return_pronoun('his/her', me.gender)>> mouth. ';
                   
                    }else{
                        
                         message =  '<<me.name>> places {the dobj/he} into 
                                <<me.return_pronoun('his/her', me.gender)>> mouth. ';
                        
                    }
                    
                    if(isFresh)
                    {
                        
                        message += '<<one of>>Fresh and delicious. 
                                    <<or>> It tastes good. 
                                   <<or>> It\'s great. 
                                    <<or>> Couldn\'t be fresher. ';
                            
                    }
                    
                  if(isDry)
                    {
                       
                        message += ' <<one of>>it\'s a bit dry and textury to chew on.<<or>> It\'s so dry,
                           it\'s hard to chew.<<end>>';
                        
                        me.thirstBar -=1;
                        
                        if(me.thirstBar < 0)
                        {
                            me.thirstBar = 0 ;
                        }
                    
                    }
                
                    if(isSalty)
                    {
                        
                        message += 'It\'s quite salty to the tongue.';
                        
                        me.thirstBar -= 2;
                        
                        if(me.thirstBar < 0)
                        {
                            me.thirstBar = 0 ;
                        }
                    
                    }
                
                   if(isBurnt)
                    {
                        message += '<<one of>>This is like eating charcoal.<<or>> This is worst than chewing
                            on a burn, fresh from a campfire.';
                    }
                
                    if(isSpicy)
                    {
                    
                        message += '<<one of>>{The dobj/he} is spicy, causing the taste buds to dance.<<or>>
                                It\'s so spicy it makes the mouth a little dry.<<end>>';
                        
                        me.thirstBar -=1;
                        
                        if(me.thirstBar < 0)
                        {
                            me.thirstBar = 0 ;
                        }
                    
                    }
                
                    if(isSour)
                    {
                    
                        message += '<<one of>> Bitterness causes <<me.return_pronoun('his/her', me.gender)>> lips
                            to pucker.';
                    
                    }
                
                    if(isSovory)
                    {
                    
                        message += 'It\'s a bit savory on the palate.';
                    
                    }
                
                    if(isRotten)
                    {

                        message += '{the dobj/he} tastes putrid. It\'s rotten!';
                        
                    }       
                
                "\n\b";
                    
                    // handle eating of non-rotten food
                if(!self.isRotten)
                {
                      
                    me.hungerBar += self.nutrition;
                  "<<message>>\n";
                    "\t Hunger +<<self.nutrition>>\n";
                
                }else{
            
                        me.hungerBar -= self.nutrition;
                        "<<message>>\n";
                        "\t Hunger -<<self.nutrition>>\n";
                
                        // character also looses around 10% of max life
                        amount = new BigNumber(me.hpMax * 0.25, 2);
                        amount = amount.getCeil();
                        realAmount = new BigNumber(rand(amount) + (amount + (amount/2)), 2);
                        realAmount = realAmount.getCeil();
                        me.hp -= realAmount;
                        "\t Hp -<<realAmount>>\n";
            
                        if(me.hp < 0)
                        {
                            me.hp = 0;
                        }
                   
                    // end eating rotten food
                  }
                if(me.hungerBar > me.maxHunger)
                {
                    
                    me.hungerBar += me.maxHunger;
                    
                }
                    
                // BUG: add effect code for food.
                // hasEffect
                  // apply the effect in the food.
                
                // end if gActor == me (handle eat for npx)
            }else{
                 
                // BUG : handle rotten food for NPC
                if(gDobj.isPlural)
                    {
                        
                        message =  '<<me.name>> places some of {the dobj/he} into 
                                <<me.return_pronoun('his/her', me.gender)>> mouth. ';
                   
                    }else{
                        
                         message =  '<<me.name>> places {the dobj/he} into 
                                <<me.return_pronoun('his/her', me.gender)>> mouth. ';
                        
                    }
        
                    "\n";
                    gActor.hungerBar += self.nutrition;
                    "\t Hunger +<<self.nutrition>> (<<gActor.name>>)";
                    
                if(gActor.hungerBar > gActor.maxHunger)
                    {
                        
                        gActor.hungerBar += gActor.maxHunger;
                        
                    }
                    
                // end if gActor == npc
            }
        
            if(gDobj.uses <= 0)
            {
        
                gDobj.moveInto(nil);
                gDobj.location = nil;
                
            }
    
                
            }else{
                
                "<<gActor.name>> isn't hungry enough to eat {the dobj/he}.";
                
            }
            
        // end action
    }
    
  // end dobjFor eat  
}
    // remove food if eaten

afterAction()
{

    if(self.uses <= 0)
       {
        
    
            self.moveInto(nil);         
       
       }

    food_handler();

}


// food_handler for rotting food
// BUG : Finish food handler
food_handler()
{
    
    self.shelfLife -= 1;
    switch(self.shelfLife)
    {
       
        case 25:
            "<<one of>>Something is beginning to smell a little funny. 
            <<or>> Something smells a bit off.
            <<or>> Something doesn't smell right.";
        break;
        case 0:
            "<<one of>>Something smells rotten. 
            <<or>> Something smells putrid.
            <<or>> A putrid smell wafts up from somewhere.";
            self.isRotten = true;
            self.name = 'rotten ' + self.name;
            self.vocabWords = 'rotten <<self.name>>';
            isFresh = nil;
            isSalty = nil;
            isSour = nil;
            isSweet = nil;
            isSpicy = nil;
            isSavery = nil;
            isBitter = nil;
        break;
    
    }
}

;
[/code]

Why? That’s something from I’m trying to lead you away…

I’ve searched library code and it seems the problem is same as with vocabWords, on Thing class there is a method initializeThing() which checks whatever the isEquivalent property is set to true and then it calls initializeEquivalent() which does some magic to make it work.

You should use the library the way it is designed to be used, else you will run into lots of problems which are hard (and unnecessary!) to solve without detailed knowledge of the library source code. Search for source code of Return to Ditch Day or Mrs. Peppers Nasty Secret games and read it through to get some idea of coding style for which the library is optimized. You’ll see you can do lots of things purely declaratively by assigning values to properties of objects and classes before writing any method. TADS is weighted to declarative approach quite a lot and does some processing on background to make everything work and when you try to go around and do something no manual told you to do, then well, you need to know what you are doing.

Sorry, I didn’t mean to click the pm button, I thought I was replying to thread. Just so others know what I said, I basically just dropped the constructor from Food, and asked if I could instantiate food without the extra sorrel class.

Making a class is a way to declare properties before the object is instantiated. I think it is also quite natural - you need number of same objects therefore you make a class of objects and then instantiate how many you like. I think its also more readable and makes code terse.

Or maybe you can look from different perspective. You want your objects to be treated interchangeably therefore you marked them as isEquivalent = true. Now if you lookup documentation, you’ll note that equivalent object should be of the same immediate superclass and marked with the equivalence flag to be treated equivalently. Do you want all Food to be treated equivalently? You have sorrels, but what you will do when you add apples to your game? Sure one sorrel should be equivalent with other sorrels and an apple should be equivalent to other apples, but apple should not be considered equivalent to sorrel. Therefore Food as a general class should not be marked with isEquivalent flag, rather certain subclass representing certain type of food.