I’m having trouble trying to get some ConvNode logic to work in this cardgame library where what I’m trying to do is basically this:
When an NPC actor decides to start a game, if that NPC is designated to be the dealer, then that NPC will be given a new instance of the BlackjackDealing actor state (I make a new instance of it at runtime), and that instance will be added to the actor in question (moved into its inventory, as if it had been defined with a “+” operator under the actor’s definition in the source code).
But it doesn’t work. Specifically the ConvNodes inside that ActorState don’t work.
I suspect it’s because ActorStates do not function correctly if you use moveInto() to add them to the actor’s inventory at runtime. They had to be there already at compile time because of some initialization code run at startup.
What I’m asking is this: Is the above statement true? If so I have to design things differently.
Why I am thinking this might be the case is because of this code in the adv3 library file: /usr/local/share/frobtads/tads3/lib/adv3/actor.t, line 501 :
/* preinitialize */
execute()
{
/* add every ConvNode object to our master table */
forEachInstance(ConvNode,
{ obj: obj.getActor().convNodeTab[obj.name] = obj });
/*
* set up the prompt daemon that makes automatic topic inventory
* suggestions when appropriate
*/
new PromptDaemon(self, &topicInventoryDaemon);
}
This is run inside of conversationManager which is a kind of PreinitObject, meaning this is a bit of code that will run prior to the first turn of the game. Note the use of “getActor()” in the above call. calling a ConvNode’s getActor() method will abort with a nil reference error if the ActorState that the ConvNode is part of isn’t inside of an actor at the time. (Which is how I found out about this bit of code. At first it was crashing because my BlackjackDealing ActorState was defined without using the “class” keyword so there was an instance of it at preInit time and this code was trying to operate on that instance. I got rid of that error by making it a class, but when I think about the logic in use here, it seems like getting rid of the runtime error by doing that still won’t make the logic actually work if this all important initialization step was skipped.)
The implication I am getting from this is that the library expects all ConvNode objects to already be located inside ActorStates that are in turn already located inside an actor at compile time.
Therefore this sort of logic doesn’t work, I think:
// During the game, when a blackjack minigame begins, run this code:
//
// assume BlackjackDealing is a subclass of ActorState that contains one or more ConvNodes inside it that drive how the dealer will react to statements like "ask <<name>> for card".
// assume act is a variable referencing an instance of Actor who is to become the dealer of this game.
local dealerNode = new BlackjackDealing;
dealerNode.moveInto(actor);
act.setCurState(dealerNode);
// I have just "given" the BlackjackDealing ActorState to the act actor, but the ConvNodes inside that state don't work.
Am I correct? If so the implication is that all actors must contain hardcoded at compile time inside of them all the ActorStates that they might switch to during the course of the game.