Calling property routines

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

Bainespal
Posts: 151
Joined: Fri Jul 09, 2010 8:59 am

Calling property routines

Post by Bainespal »

I just have a quick question this time. How can I call and run a property routine (specifically, an after routine) from outside of the parent object? simply putting "object.after" doesn't work, producing the compiler error "Missing assignment: =". Putting empty parenthesis after it as when calling a stand-alone routine with arguments ("object.after()") does not make a difference.

The code does not appear in a condition. I know that testing for a property will sometimes inadvertently run the property unless you use the "&", but that doesn't apply here.

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

Post by Roody_Yogurt »

I'd be curious as to what circumstances are calling for this, but yeah, it's possible. The main thing is that you have to set the verbroutine global variable so the right part of the after routine is run, like so:

Code: Select all

verbroutine = &DoListen
run stables.after
(Which would run the stable room's after DoListen routine, of course)

Bainespal
Posts: 151
Joined: Fri Jul 09, 2010 8:59 am

Post by Bainespal »

I must have forgotten about the run directive. Thanks for pointing out that I need to set the verbroutine, too. Now it compiles, at least, but it still doesn't do what I want.

The PC has a plate on which is a meal object that he eats as part of the scene (the object counts the number of bites taken, but that code doesn't affect this). If the player tries to eat without holding three silverware objects, the game asks, "What, with your fingers?" using the Informal Questions code. If the player responds, "yes", the same action that happens without a question if the PC is holding the silverware is triggered, but a different suffix is printed after the message (", picking it up messily with your hands.").

The library DoEat verb appears to be designed to be implemented in after routines. Therefore, the actions taken in response to eating the meal are implemented in your_meal.after, including the printed message. There's a condition in after to print a period if the PC is holding the silverware, because then the suffix about eating with your hands hasn't been printed.

I decided to check if the PC is holding the silverware and to call NewQuestion in before, since its naturally called before after gets a chance.

I could test for whether or not the silverware is carried in the same routine in which the main code for handling DoEat is located, but I would still need a way to jump back to the main DoEat code, to print the message and execute the rest of the code. I thought it would be easier to go back and forth if I used both before and after. What I ultimately need to do is call your_meal.after from DoYes, and then go back to DoYes to print the suffix.

This is the only way my brain can conceive of structuring this code. Maybe I'm making it more complicated than it needs to be. Sorry to waste your time. :)

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

Post by Roody_Yogurt »

My first idea involved doing more Informal Question-type stuff, but I think the easiest thing to do would be to just create dummy verb routine to run the eat-with-bare-hands text and code, like so:

Code: Select all

object your_meal "your meal"
{
	before
		{
		object DoEat
			{
			if not Contains(player,silverware)
				{
				"What, with your bare hands?"
				NewOpp(ifbarehands)
				return true
				}
			return false
			}
		}
	after
		{
		object DoEat
			{
			"You eat the food daintily with your silverware."
			}
		}
}

routine DoEatBareHands
{
	"You eat the food, picking it up messily with your bare hands."
	! other food code
}

replace DoYes  ! this routine assumes VERBSTUBS has been included
{
	if not current_opp
		{
		"Yes?"
		return false
		}
	else
	select current_opp
		case ifbarehands: {
								Perform(&DoEatBareHands)
								return true
								}
	return true
}

Bainespal
Posts: 151
Joined: Fri Jul 09, 2010 8:59 am

Post by Bainespal »

I had thought about making an independent routine, but couldn't picture how it would work. It turns out it was almost as simple as combining the code I had in DoYes and in the after routine into the new routine, and then simply calling that new routine from both places. Before returns false if the PC was using silverware to begin with, passing to after, which passes to FingerFood().

Thanks!

Incidentally, I'm a bit disappointed with Hugo for not doing what I expected once I had the directive to run your_meal.after in there correctly. Looking at the Debugger, it read that line and the one above it setting verbroutine, but did absolutely nothing. Oh, well. That doesn't matter anymore; the code works, and it's really more logical this way. :-)

Post Reply