matching a command to an attribute?

XanMag
10 Feb 2016, 22:59
Just out of curiosity, can you match a command to a shared attribute? I'm not even sure I am asking that correctly. :roll:

For example, if I have this as a regular expression command (assuming it would work):

^(pour|dump|add|empty|put|use) (the |)(bottle|water|bottle of water) (on|over|into|onto) [attribute]

The [attribute] here would be anything in my game that I gave that attribute to. Maybe, I want to give the attribute "plant" to several objects in my game and would like an appropriate response for each plant object. Or maybe, for some reason I want to give the attribute "NPC" to all humans and would like a response for pouring water on the NPCs. Does that make any sense?

I know I could replace the attribute with #object# and do an If/Else if/Else If/etc.../Else to check if the object is a water source, but that's not what I am going for. Again... I'm not entirely sure that explanation (#object#) is accurate but hopefully you get what I mean?

Sorry if this is a stupid question, but I'm sure you all are used to them! Thanks in advance!

Cylius_Optimi
11 Feb 2016, 02:07
You could use types & inheritance to define a default response string or script for a certain command; such as a "obj_plant" type with a "pouron" attribute; come to think of it, that could work for both verbs and commands.

Something like:

<command name="PourOnOrWhateverYourCommandNameIs">
if (HasAttribute (object, "pouron")) {
do (object, "pouron")
} else {
msg ("You can't do that.")
}
</command>

<type name="obj_plant">
<pouron type="script">
msg ("The plant appreciates the water. You don't know how you know this, but it does.")
</pouron>
</type>

<type name="npc_person">
<pouron type="script">
msg ("They probably wouldn't appreciate that as much as a plant would.")
</pouron>
</type>


If you'd like some further explanation, I'd be glad to help.
EDIT: Also, my example does have a flaw in that it doesn't remove the water if you use the object on a plant, but it still holds.

XanMag
11 Feb 2016, 03:45
Types... I am confused by them. I get the first half of that, but I am unsure of the second half. I don't understand --> <type name="obj_plant">
<pouron type="script">

By now, I should get it, but I do not.

Also, keep in mind, I am trying to explain in my tutorial using the GUI. If I understood this code, I'm sure I could go back and forth between code view and the GUI and figure out how to implement this using the GUI only.

If this is too difficult to generate using GUI only, I still would like to know how to do this for future reference.

Thanks!

Cylius_Optimi
11 Feb 2016, 03:54
XanMag wrote:Types... I am confused by them. I get the first half of that, but I am unsure of the second half. I don't understand --> <type name="obj_plant">
<pouron type="script">

By now, I should get it, but I do not.

Also, keep in mind, I am trying to explain in my tutorial using the GUI. If I understood this code, I'm sure I could go back and forth between code view and the GUI and figure out how to implement this using the GUI only.

If this is too difficult to generate using GUI only, I still would like to know how to do this for future reference.

Thanks!


Sorry, I'm just so used to editing my code directly that I didn't think to explain that bit.

By default, Object Types in the GUI are hidden out of the way; that's good for keep a newbie from feeling overloaded, but bad for when they actually want to find it. You can find them in root -> Advanced -> Object Types. (root being the top level of the pane to the left; ie not within any category.) I'd suggest you keep your own custom types memorable (ie Plant), but you can go with my choice of "obj_whatever"; it's just a matter of preference.

After you create an object type, you can edit it's attributes just like a normal object. Then, when you're done, you can use the top pane in the Attributes tab of any object to "inherit" your custom Object Type to it. Then, any attributes defined by your Type will apply to that object, without having to manually define them.

The tag <pouron> is what would likely occur when you create a verb named Pour On and add it to an object. It's just a script attribute, but defined in Quest's XML.

HegemonKhan
11 Feb 2016, 07:47
here's some posts so far I've found of mine about Object Types:

viewtopic.php?f=10&t=5450&hilit=object+types
viewtopic.php?f=10&t=5356&hilit=object+types

------------------

Think as an Object Type (quest's Classes/Groups) as an Object that is a container of Attributes (and/or other Object Types), which you can give to the Objects you want to have that pool of Attributes held by that Object Type. Basically, Object Types are a way of giving multiple Objects, the same (large) collection of Attributes.

Or maybe another way to describe of it: think of an Object Type as "cloning" for a large collection of Attributes.

The Pixie
11 Feb 2016, 09:25
XanMag wrote:Just out of curiosity, can you match a command to a shared attribute? I'm not even sure I am asking that correctly. :roll:

For example, if I have this as a regular expression command (assuming it would work):

^(pour|dump|add|empty|put|use) (the |)(bottle|water|bottle of water) (on|over|into|onto) [attribute]

The [attribute] here would be anything in my game that I gave that attribute to. Maybe, I want to give the attribute "plant" to several objects in my game and would like an appropriate response for each plant object. Or maybe, for some reason I want to give the attribute "NPC" to all humans and would like a response for pouring water on the NPCs. Does that make any sense?

I know I could replace the attribute with #object# and do an If/Else if/Else If/etc.../Else to check if the object is a water source, but that's not what I am going for. Again... I'm not entirely sure that explanation (#object#) is accurate but hopefully you get what I mean?

Sorry if this is a stupid question, but I'm sure you all are used to them! Thanks in advance!

Another way to do it is to check for the attribute in your if/else blocks

^(pour|dump|add|empty|put|use) (the |)(?<object_1>.*) (on|over|into|onto)(?<object_2>.*)$


if (not GetBoolean(object_1, "full_of_water")) {
msg("You try to pour from the " + GetDisplayAlias(object_1) + " but there is nothing in it.")
}
else if (not GetBoolean(object_2, "can_be_poured_over")) {
msg("You can't go around pouring stuff on any " + GetDisplayAlias(object_1) + " you find lying around.")
}
else {

jaynabonne
11 Feb 2016, 12:24
Would it work to simply give "plant" as a an alias for the various plant-y things? Then if you just use %object%, it will match "plant" as a noun as well.

If you want them to be able to type "pour the water on plant", then it seems you'd want them to be able to "x plant" and "take plant" as well. Otherwise, you'd have "plant" only work for some things but not others. Providing an alias makes it work in general.