Trouble using a class as a template

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Trouble using a class as a template

Post by Tdarcos »

I have a number of items that have some attributes and properties that are the same, so I wanted to use a class. Note that the Coke can is the same as diet coke or pepsi, they're in a class to make the parameters the same, more-or-less.

Note that in the example below, &lt 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
			&#123;
				print "You need $3 for a soda.  You don't have enough money."
				return
			&#125; else &#123;
				cash.cashcount -= 3
				object is not hidden
				move object to you
				print "The machine collects $3 from you.  It dispenses "; the&#40;object&#41;; " which you take."
				return
			&#125;	
		&#125; else &#123;

! other code eliminated for this article


! from the file dealing with the soda machine

class sodacan
&#123;
	article "a"
	is	pushable, hidden, beverage
	in soda_machine
		
	before
	&#123;
		object DoDrop
		&#123;
			print "Drop Code in player"
			return false
		&#125;
	&#125;
&#125;

object coke "12-ounce can of Coca-Cola"
&#123;
	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
	&#123; bottler &#40;"COKE",Maker_Coke&#41; &#125;		
		
	before
	&#123;
		object DoDrop
		&#123;
			print "Drop Code in player"
			return false
		&#125;
	&#125;
	
&#125;

sodacan dietCoke "12-ounce can of diet Coke"
&#123;
		adjectives "coke","diet","cola","cocacola","coca-cola"
		long_desc
		&#123; bottler &#40;"DIET COKE",Maker_Coke&#41; &#125;
&#125;

sodacan pepsi "12-ounce can of Pepsi"
&#123;
		noun "pepsi"		! So "push" pepsi or "take" pepsi uses this ahead of max
		adjectives "cola"
		long_desc
		&#123; bottler &#40;"PEPSI",Maker_Pepsi&#41; &#125;
&#125;

This compiles okay.

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.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

Roody_Yogurt
Posts: 2256
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Post by Roody_Yogurt »

It seems a bit strange that the sode cans themselves are pushable. Usually in such cases, people make button objects for the soda machine, possibly as 'components'.

Anyhow, it looks like the problem is that the player can't actually see these sodas (and make them be known). Seems you're going to have to give the soda machine the open attribute or make it transparent or something.

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Post by Tdarcos »

Roody_Yogurt wrote:It seems a bit strange that the sode cans themselves are pushable.
Well, it's like this:

Code: Select all

object soda_machine "soft drink vending machine"
&#123;
	article "a"
	in Store_3_06
	adjectives "soda","coke","vending","machine"
	is switchable		! can be plugged in
	
	long_desc
		"This is a full-size electric vending machine that dispenses soda.  It has twelve selections&#58;\n
		Coke\n
		Diet Coke\n
		Pepsi\n
		Pepsi Max\n
		Fanta Strawberry\n
		Diet Fanta Strawberry\n
		Fanta Orange\n
		Mtn. Dew\n
		Diet Mtn. Dew\n
		Dr. Pepper\n
		Diet Dr. Pepper\n\n
		PUSH the button of that name for that selection.  The money will be automatically collected."
I'm using the sodas as both the button for the item, and the item itself. I suppose I can put some default item directly that can be pushed.
Usually in such cases, people make button objects for the soda machine, possibly as 'components'.

Hmm, never thought of that.
Anyhow, it looks like the problem is that the player can't actually see these sodas (and make them be known). Seems you're going to have to give the soda machine the open attribute or make it transparent or something.
Excellent, I'll try making the vending machine transparent. I mean, I have a "fan" class because i have several fans in places, they're powered, they can be turned on and off and the responses for using them are the same, so all of the fans are of the fan class. I wanted to do the same thing with the soft drinks.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Post by Tdarcos »

Before someone notices there's only 11 items and it says there are 12, I have to add diet orange.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Post by Tdarcos »

Making the vending machine transparent didn't help. I'll probably use a component and parse the values.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

Roody_Yogurt
Posts: 2256
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Re: Trouble using a class as a template

Post by Roody_Yogurt »

Tdarcos wrote:Note that in the example below, &lt 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.
I've found that using the "Disable HTML in this post" option when posting fixes this problem.

User avatar
Tdarcos
Posts: 9556
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Post by Tdarcos »

I solved the problem. I had the vending machine have a series of buttons from 10 to 21 for the items, and PUSH 15 or PUSH 20 to release the can.

So I have the cans of soda different from the push buttons.
It looks like the game - which is called Tripkey - will be available for release today, exactly 30 days after I started it, which was 9/9. I was considering being symmetric, and releasing it (for beta testing) on 10/10.
"When I die, I want it easy and peaceful in my sleep, like my uncle.
Not screaming and crying like his passengers."

Post Reply