Inheritable topic responses

pretty simple, is there any way to make topic responses inheritable or specific to a class. For example.

modify Actor


;

+ GiveTopic @coin
    topicResponse()
    {
        "He takes the coin, looks at it, and then vanishes having served his purpose.";
        getActor().moveInto(nil);
        
        
    }
;

modifying or making a new class, doesn’t seem to matter, I can’t figure out how to get this to work, it gives a nil reference since there isn’t an actual object in play, just a class.

This is a bit above my level so any idea how or if there is something I simply don’t get is always appreciated.

There are probably multiple approaches, but I did this type of thing in preinit, sometimes having to make a class for the topic response that was going to be in all Actors (or a subclass thereof), and using forEachInstance to call addTopic.
Let me know if you need more details…

more details would be lovely, my attempt doesn’t seem to be working… here is my attempt at how you described it.

#charset "us-ascii"

#include <tads.h>
#include "advlite.h"

versionInfo: GameID
    IFID = '106dc997-6138-4408-b349-10b9eb1bdeaa'
    name = 'Your New Game Title'
    byline = 'by Your Name'
    htmlByline = 'by <a href="mailto:your-email@host.com">Your Name</a>'
    version = '1'
    authorEmail = 'Your Name <your-email@host.com>'
    desc = 'Put a brief "blurb" about your game here'
    htmlDesc = 'Put a brief "blurb" about your game here'
;

gameMain: GameMainDef
    /* Define the initial player character; this is compulsory */
    initialPlayerChar = me
;



appTopics: PreinitObject
    execute()
    { 
        
        forEachInstance(Actor, new function(actor) {local newtopic = new cTopic(); actor.addTopic(newtopic);});
            
    }
;

class cTopic: GiveTopic
           matchObj = [coin]
    
    
    
     
    topicResponse()
    {
        "They take the tokennyyyyyyy";
    }
;

coin: Thing 'coin' @me
;

/* The starting location; this can be called anything you like */

startroom: Room 'The Starting Location'
    "Add your description here. "
;

/* 
 *   The player character object. This doesn't have to be called me, but me is a
 *   convenient name. If you change it to something else, rememember to change
 *   gameMain.initialPlayerChar accordingly.
 */

+ me: Player 'you' 
   
;

+bob: Actor 'bob'
    
;

+steve: Actor 'steve'

;

However, when I try to give the coin to one of our friendly faces, we get a nil object error pointing to this line in ‘actor.t’

active = (isActive && activated && location.active)

I’m assuming you’re using adv3Lite, because I’m not familiar with the condition line. It looks to me like you need to manually set the location property of the cTopic in preinit so you don’t get the nilobjref. (newTopic.location = actor, before addTopic)

that was exactly it, thank you very much!

1 Like

Note that if you don’t do any subclassing or filtering, your forEachInstance loop is going to add that topic to every Actor including the player character…

Haha, yeah I’m aware. This was just for this simple stress test, in my actual project there’s a specific class that’ll be iterated through instead of just the generic ‘actor’ one.

1 Like