Adding verbs

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

Hugella

Adding verbs

Post by Hugella »

Can 'new' verbs i want to include in my game be #included in a file (#include myverbs.g) or do they have to be declared in the main game file (before the grammar?)

Kent
Posts: 119
Joined: Fri Jun 27, 2003 12:10 pm

Either

Post by Kent »

They can be #included in a separate file, either before or after the game grammar. Guilty Bastards, for instance, has this in guilty.hug:

Code: Select all

! Grammar must be included before anything else:
!
#include "verblib.g"            ! normal verb library grammar
#include "gb.g"                 ! game grammar

#include "moreverb.g"
Now, what this means is that verbs in verblib.g take precedence over gb.g. If you wanted to override verblib.g's grammar, you'd need to define some grammar before it.

Basically think of #included files as being all part of the same big source file--that's the way the compiler looks at it, anyway.

User avatar
Ice Cream Jonsey
Posts: 30193
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post by Ice Cream Jonsey »

Hey, can you have conditions for "living" and "object" for the same verb? I.E. -- and I don't mean that crappy Browser!!!!

Code: Select all

verb "spit"
	*						DoVague
	* living					DoSpitLiving
	* "on" living					DoSpitLiving
	* "at" living					DoSpitLiving
	* object					DoSpit
	* "on" object					DoSpit
	* "at" object					DoSpit




routine DoSpitLiving
{
	if object.conscious = 0
	{
		"I hock a sizeable loogie and let go."
	}
	else
	{
		"Being brought up by Old Man Duffy gets in the way of spitting in a face!"
	}
}




routine DoSpit
{
	"I try to keep the city clean, eh?"
}



... Anyway, if I try to run all that I see that it handles me trying to spit on a living object OK, but it won't invoke DoSpit if I try to spit on an object.


EDIT! Also, if I try to handle talking to an object and talking to a living entity in DoTalk (for instance, I have a skull in the game and I want the PC to be able to try to talk to it, but I don't want that skull to get any of the other privledges that the living tag offers) it'll mess up in the same way.

Is there a way to make it so that I can have different default commands for spitting on animate and inanimate things?
the dark and gritty...Ice Cream Jonsey!

Kent
Posts: 119
Joined: Fri Jun 27, 2003 12:10 pm

Workaround

Post by Kent »

Yeah, as it is now, the use of an attribute as an object placeholder will interrupt parsing if it gets a grammar match whether or not the object has that attribute--i.e., you'll be passed either to the verbroutine or to a parser error. This is not ideal and should probably be changed at some point (probably by improving the parser's notion of 'best error' and having it work more intelligently through a number of possible grammar matches).

What I would recommend doing is something like:

Code: Select all

* object          DoSpitGeneral
where DoSpitGeneral would do the dispatch for you, along the lines of:

Code: Select all

routine DoSpitGeneral
{
     if object is living
          return DoSpitLviing
     else
          return DoSpit
}
Or something like that. There are a number of different ways to go about this (including just putting the test in the DoSpit[Living] routine, etc.) But this way probably abstracts it best.

User avatar
Ice Cream Jonsey
Posts: 30193
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post by Ice Cream Jonsey »

You da man, Kent. Thanks.

Now, to code the horrible wasting disease that my protagonist's spit will contain!!!
the dark and gritty...Ice Cream Jonsey!

Brazillio

Post by Brazillio »

I'm pregnant and I don't know who the father is! It could be any of you! Help me, Hugo!

Post Reply