Using the adv library, I have an ATM object that dispenses 5 $20 dollar bills at a time. When Harry gives something to a street person, I am able to use a GiveTopic to provide dialog…
[code]+ GiveTopic
matchTopic(fromActor, obj)
{
return obj.ofKind(Thing) ? matchScore : nil;
}
handleTopic(fromActor, obj)
{
if(obj.ofKind(twentyDollarBill))
obj.moveInto(getActor());
gTranscript.addReport(new AcceptItemReport(obj));
}
;
class AcceptItemReport: MainCommandReport
construct(obj)
{
if(obj.ofKind(twentyDollarBill))
{
gMessageParams(obj);
inherited('The man quickly snatched {the obj/him} from Harry's hand. ');
}
else
{
gMessageParams(obj);
inherited('The homeless man reached to grab it, but Harry
reconsidered giving away {the obj/him} and withdrew his hand.
<.p>
“Erghhh,” the other man snarled as his fist closed on empty
air. ');
}
}
;[/code]
But when I try to port this to work with adv3lite, I find that GiveTopic code has been redefined in a new library file called TopicEntry.t, and matchTopic() now takes only one argument, obj. When I fix that, I find that handleTopic() now takes no arguments. When I fix that, I am able to give 4 20s to a store clerk , but when I then try to look inside Harry’s wallet, I get a runtime error that says
The Workbench code pointer points to local entry = words|i| in thing.t…
[code]matchToken(tok, words, cmp)
{
/* we don’t have a match for this token yet */
local strength = 0, partOfSpeech = 0;
/* try matching this token against our vocabulary list */
for (local len = words.length(), local i = 1 ; i <= len ; ++i)
{
/* get this vocabulary word entry */
local entry = words[i];
[/code]
Yes, I shifted milieus, Harry’s now in a store buying something, no longer giving money away to the street person, but the coding problem exists in both places. The store scene is where I really need to solve the problem. How can I get it to work so that Harry is able to give away an arbitrary subset of the number of 20s he has in his wallet? I also want to control the dialog exchange while this is going on, which is why I’m trying to use a GiveTopic.
It’s getting a bit long, but here it is anyway, the current test-bed game code…
[code]#charset “us-ascii”
#include <tads.h>
#include “advlite.h”
versionInfo: GameID
IFID = ‘243748b1-5310-4916-8436-890e9ccc16fd’
name = ‘test’
byline = ‘by Jerry Ford’
htmlByline = ‘by
Jerry Ford’
version = ‘1’
authorEmail = ‘Jerry Ford jerry.o.ford@gmail.com’
desc = ‘Testing adv3lite GiveTopic.’
htmlDesc = ‘Testing adv3lite GiveTopic.’
;
gameMain: GameMainDef
/* the initial player character is ‘harry’ */
initialPlayerChar = harry
paraBrksBtwnSubcontents = nil
usePastTense = true
;
// harry, main character
harry: Actor ‘Harry;;man self’ @streetCorner
“”
contType = Carrier
globalParamName = ‘harry’
isFixed = true
isHim = true
isInitState = true
ownsContents = true
person = 3
proper = true
bulkCapacity = 5000
hasShowered = nil
;
-
wallet: Container ‘wallet;;wallet’
"The bifold wallet showed frayed corners and cracks of age etched
into the brown leather. "
;
// items hidden in harry’s wallet
++ debitCard: Surface, Thing ‘debit card;;card’
"Harry’s debit card gave him instant access to his checking
account. "dobjFor(PutIn)
{
action()
{
if(gIobj.ofKind(atm))
{
say('When Harry inserts the debit card into the machine, it
becomes operational. Harry enters his PIN and withdraws
$100 in 20s, retrieves the card, and puts it back into
his wallet. ');
atm.loadWallet();
self.moveInto(wallet);
}
}
}
;
// the street corner and the ATM machine
streetCorner: Room ‘Street Corner’ ‘street corner’
"The corner of the street. An ATM was built into the wall of the apartment
building. "
south = store
;
- atm: Container, Immovable ‘an ATM;automated teller ;machine ATM’
"An automated teller machine. "
initiallyOpen = true
canPutIn(obj) { return obj.ofKind(debitCard); }
loadWallet()
{
for(local i = 0; i < 5; i++)
{
local twentyDollarBill = new TwentyDollarBill;
twentyDollarBill.moveInto(wallet);
}
}
;
// money class
class Dollar: Thing
vocabWords = ‘dollar bill;bills’
;
class TwentyDollarBill: Dollar ‘20; twenty’
isEquivalent = true
dollarValue = 20
dollarGroupBaseName = ‘twenty’
;
class TenDollarBill: Dollar ‘10; ten’
isEquivalent = true
dollarValue = 10
dollarGroupBaseName = ‘ten’
;
class FiveDollarBill: Dollar ‘5; five’
isEquivalent = true
dollarValue = 5
dollarGroupBaseName = ‘five’
;
class OneDollarBill: Dollar ‘1; one’
isEquivalent = true
dollarValue = 5
dollarGroupBaseName = ‘one’
;
// the store
store: Room, Container ‘Store’ ‘store’
“"Harry, my man. Special price, today only, for
you, just $100. What’dya say? Gimme some plastic, I’ll wrap it
right up. Make it cash, and the price is just $80."”
south = streetCorner
;
- gizmo: Thing ‘gizmo’
"It’s a gizmo. "
;
// the store clerk
harv: Actor ‘Harv;heavy heavyset hefty bearded shop;man clerk;him’ @store
“”
contType = Carrier
globalParamName = ‘harv’
isFixed = true
isInitState = true
ownsContents = true
person = 3
proper = true
bulkCapacity = 5000
;
- GiveTopic
// matchTopic(fromActor, obj)
matchTopic(obj)
{
// return obj.ofKind(Thing) ? matchScore : nil;
return obj.ofKind(TwentyDollarBill) ? matchScore : nil;
}
// handleTopic(fromActor, obj)
handleTopic()
{
// if(obj.ofKind(TwentyDollarBill))
// obj.moveInto(getActor());
TwentyDollarBill.moveInto(getActor());
}
;
[/code]