Page 1 of 1

Adding verbs

Posted: Tue Dec 09, 2003 9:21 am
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?)

Either

Posted: Tue Dec 09, 2003 12:20 pm
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.

Posted: Tue Dec 09, 2003 9:00 pm
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?

Workaround

Posted: Tue Dec 09, 2003 10:23 pm
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.

Posted: Wed Dec 10, 2003 1:02 am
by Ice Cream Jonsey
You da man, Kent. Thanks.

Now, to code the horrible wasting disease that my protagonist's spit will contain!!!

Posted: Wed Dec 10, 2003 2:35 pm
by Brazillio
I'm pregnant and I don't know who the father is! It could be any of you! Help me, Hugo!