Note that in the example below, < is actually a less-than sign which I had to obfuscate for this article; if I leave that symbol in the code, the BBS software eats the code display and this message is corrupted.
Code: Select all
! from tripkey.g
verb "push","press"
* DoVague
* pushable DoPush
* "b"/"1"/"2"/"3" DoElevator
! from tripkey.h
Routine DoPush
{
! other code dropped for demo purposes this article
} elseif (object is beverage) { ! Pushing sodas on machine
if cash.cashcount < 3
{
print "You need $3 for a soda. You don't have enough money."
return
} else {
cash.cashcount -= 3
object is not hidden
move object to you
print "The machine collects $3 from you. It dispenses "; the(object); " which you take."
return
}
} else {
! other code eliminated for this article
! from the file dealing with the soda machine
class sodacan
{
article "a"
is pushable, hidden, beverage
in soda_machine
before
{
object DoDrop
{
print "Drop Code in player"
return false
}
}
}
object coke "12-ounce can of Coca-Cola"
{
article "a"
is pushable, hidden, beverage
in soda_machine
nouns "coke" ! naked Coke uses this instead of diet
adjectives "cocacola","coca-cola","cola"
long_desc
{ bottler ("COKE",Maker_Coke) }
before
{
object DoDrop
{
print "Drop Code in player"
return false
}
}
}
sodacan dietCoke "12-ounce can of diet Coke"
{
adjectives "coke","diet","cola","cocacola","coca-cola"
long_desc
{ bottler ("DIET COKE",Maker_Coke) }
}
sodacan pepsi "12-ounce can of Pepsi"
{
noun "pepsi" ! So "push" pepsi or "take" pepsi uses this ahead of max
adjectives "cola"
long_desc
{ bottler ("PEPSI",Maker_Pepsi) }
}
And as a result, I get this at run-time:
3rd Floor: Escalator down
Go WEST to Department 6, or take escalator DOWN to Second Floor.
>w
Third Floor Department 6.
Go SOUTHWEST to the elevator, or EAST to the escalator.
A soft drink vending machine is here.
>push coke
The machine collects $3 from you. It dispenses the 12-ounce can of Coca-Cola which you take.
>i
You have $7 cash.
You are also carrying the magical tripkey and a 12-ounce can of Coca-Cola.
>push pepsi
You haven't seen anything like that.
>push diet coke
You haven't seen anything like that.
Mainly I don't want to have to repeat the before code for each item. But I'm not sure why it doesn't work as a member of a class but does work as an object.