Question about Commands and Verbs

cbernard
26 Apr 2014, 04:18
Suppose I want to create several readable objects. I create a type 'readable' with the 'readable' attribute, then assign each readable thing to this type. Then, I create a 'read #object#' command to handle reading readable things. So far so good. But what if I want to make one readable thing react differently to the read command? My instinct was to make a 'read' verb for this object, assuming that it would take precedence over the command with the same name, but this does not seem to work.

How can I achieve this functionality in the easiest way? I think that as a last resort, I could add a special case for the one object to my read command, however, this seems clunky, and if I had many specific books as exceptions, it would clutter my command quickly. Surely there's a better way?

Pertex
26 Apr 2014, 09:58
cbernard wrote: But what if I want to make one readable thing react differently to the read command?


What are the different reactions that should happen? Just printing a specific text or executing different scripts?

cbernard
26 Apr 2014, 16:03
Well, right now I'm just thinking about printing different messages, but I would also like to know how to do it for scripts, if that calls for a different strategy.

jaynabonne
26 Apr 2014, 19:04
I think I would have to ask what would be the gain with a readable type and new command when Quest already has the "read" verb built in that allows you to have per-object text or script handling. Unless you have a lot of common code among all readable objects, it seems they're going to need to diverge anyway...

But let's assume that you do want common code or behavior among a large group of readable objects, such that they generally aren't customized. What I'd do is have your readable type but keep the "read" verb - just put your common behavior in the base readable type's "read" handler. Then if you have an object that needs to diverge, it just defines it's own read handler.

In other words, forget a custom read command. Just put what would be in the command in the base type's "read" script attribute.

HegemonKhan
26 Apr 2014, 19:52
could you explain your game design idea (what you want to do) in a bit more detail, as it would help us to design a code for it:

HK Edit: after reading Jay's post, I forgot that there's already a built-in "read" Script~Verb, so either use that, or create your own custom Verb, such as "examine" (hopefully this isn't a built-in Verb too... lol. I really need to learn all the built-in game stuff a lot more, sighs ~ so many things to learn...)

Objects have a built-in "description" Script Attribute, which you can use for a 'readable' Script, or you can create your own Script (verb) too, if you want also a more specific 'read' (an actual action) than just only a more general 'description' of an Object. (because, as of right now, with what you posted, I don't think you really need a 'readable' Object Type used for your Objects)

Do you want your Objects to only have 1 action (a Script), such as 'read' (a 'msg' Script~Verb), or do you want to have a choice of multiple actions (Scripts~Verbs, be they all different 'msg' scripts or other whatever Scripts) that it would do, depending on what you choose in game?

example 1: only a single action

Objects: apple, orange, lemon, lime
"msg" Script ("read" Verb) for all Objects except an orange: This is a fruit.
"msg" Script ("read" Verb) for an orange: I love oranges.
~OR~
"eat" Script~Verb (instead of a "read" Verb) for an orange: { msg ("You eat the orange, gaining back 50 HP"); player.hp = player.hp + 50}

example 2: 'multiple topics ~ a choice of actions'

Objects: apple, orange, lemon, lime
"msg1" Script ("read" Verb) for just an apple: This is a fruit.
"msg2" Script ("read" Verb) for just an apple: It's color is red.
"eat" Script ("read" Verb) for just an apple: {msg ("You eat the apple, gaining back 100 HP"); player.hp = player.hp + 100}
"drink" Script ("read" Verb) for just an apple: {msg ("You drink the apple cider, gaining back 100 MP"); player.mp = player.mp + 100}
"msg1" Script ("read" Verb) for just an orange: This is a fruit.
"msg2" Script ("read" Verb) for just an orange: It's color is orange.
"eat" Script ("read" Verb) for just an orange: {msg ("You eat the orange, gaining back 50 HP"); player.hp = player.hp + 50}
"drink" Script ("read" Verb) for just an orange: {msg ("You drink the orange juice, gaining back 50 MP"); player.mp = player.mp + 50}
etc (lemon, lime)

or, other examples (some other design interest)....

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

generally the code method (in my limited noob code knowledge~experience~ability, lol):

you'd just also include within your Command's "pattern" (what you type in to activate the command, and it's parameters used) is #text#, though you'll need some additional complex coding too for doing it (getting it to work).

conceptually ONLY (I'd do much different code lines ~ better code design, and also this is just for understanding the idea of how it works):

Command's Pattern: read #object# and #text#
#object# gets the Object you'll be using
#text# gets what you'll be doing with that Object
if (object = apple) {
-> if (text = "read") {
->-> msg ("This is a fruit.")
-> } else if (text = "eat") {
->-> msg ("You eat the apple, gaining back 100 HP.")
->-> player.hp = player.hp + 100
-> } else if (text = "drink") {
->-> msg ("You drink the apple cider, gaining bck 100 MP.")
->-> player.mp = player.mp + 100
-> }
} else if (object = orange) {
-> if (text = "read") {
->-> msg ("I love oranges.")
-> } else if (text = "eat") {
->-> msg ("You eat the orange, gaining back 50 HP.")
->-> player.hp = player.hp + 50
-> } else if (text = "drink") {
->-> msg ("You drink the orange juice, gaining back 50 MP.")
->-> player.mp = player.mp + 50
-> }

jaynabonne
26 Apr 2014, 20:01
HK, I'm a bit lost by your example. If your pattern is "read #object# and #text#", then for object to be "apple" and text to be "drink", they'd have to type "read apple and drink".

Is that what you're trying to do?

HegemonKhan
26 Apr 2014, 20:07
my apologizes for the confusion:

my example of "read #object# and #text#" is what the Command's "Pattern" Attribute itself would look like.

but for the actual game player's typed-in input during the game, yes, it would be: read apple and drink

cbernard
26 Apr 2014, 20:10
Ok, I'm a little confused by these responses. To change the question a little, I have a door object in my game. It is not supposed to be opened -- it's just scenery. However, if the player types 'open door' then I want a special rejection message to be displayed, rather than just 'You can't open it.' However, I don't want to change the default rejection message for opening. I just want to create a special case for this door.

HegemonKhan
26 Apr 2014, 20:22
Jay or Pertex, can help you with this, as I don't what what the built-in attribute name is (or how exactly you'd access~change it) for a 'failed' "open" attempt, but it is done via that specific "door" Object's "open" Script, I believe anyways... I'm not sure if the GUI~Editor has an option~box to change the 'failed to open' msg, or if you got to change it's template, or what, lol. Needless to say, Jay or Pertex can help you quickly easily with this, as they know the built-in stuff well, unlike me as you can see, lol.

You could also... just create~set~add yor own "open" Script for the specific "door" Object, as it will over-write it's built-in "open" script, thus using what you want it to say instead.

cbernard
26 Apr 2014, 20:34
Can you help me walk through that? That's what I tried to do, but when I went to the verbs tab on my door and tried to add 'open', it said, 'That would clash with command: 'open'."

jaynabonne
26 Apr 2014, 21:10
I'm not sure why yet, but "open" seems to have it's own special circle of problems. Perhaps because it's related to containers, and also because the responses are hard-coded and not customizable... What would work trivially for other verbs doesn't work for open.

One way to do it is to create a command for that room with pattern "open door". Then it will only apply to that door in that room, and you can make it do what you like. It will override any verb behavior. For example, if you drop this into your room:

    <command>
<pattern>open door</pattern>
<script>
msg ("The door is too heavy to budge.")
</script>
</command>

then it will print the message if you type "open door" - but just in that room. And "open" will have its default behavior for other items.

cbernard
26 Apr 2014, 21:20
Ok, that worked! Thanks!