What would be more logical?

Hello.

Let's say we have a game with an NPC who will obey the player's commands.

...but the NPC has script attributes for some actions to handle them differently depending upon certain conditions.

Let's also say we also have objects (and other NPCs) with script attributes for some actions to handle them differently depending upon certain conditions.

With me?

Good. Let's keep saying stuff. . .

Our NPC who obeys our commands is Ralph.

Another NPC in the game is named Bob.

Now, Ralph has an attack script attribute, and Bob has an attack script attribute.

There is also another NPC named Jane who has an attack script attribute.

Ralph's attack attribute expects Ralph to be the attacker, but it handles most possibilities and will handle things accordingly if Ralph is the person to be attacked. Anyway, Ralph's attack script will check who is to be attacked and respond differently depending on many factors (e.g., Ralph doesn't believe a man should hit a woman; therefore he would probably not attack Jane -- unless maybe Jane was attacking Ralph and it was in self-defense).

Every other NPC's attack script is just a verb, there to handle things when the NPC is to be attacked.


Here's my question:

In what order should the attack command's script check which object has an attack attribute?

Should it check if the would-be victim has it first? Or should it check if the would-be attacker has it first?


I am purposefully not being any more specific concerning which NPC's scripts might handle what, because that's the point of this "exercise".

I can't come up with a logical, objective reason why either way would be superior to the other, but that's probably just because I'm overlooking something, though.


PS

Here's what I think (at the moment):

I think it should check the attacker first. If Ralph won't try to attack Jane, it doesn't matter if Jane has an attack script.

Also, Ralph's attack script should check if the victim has an attack script just before going through with Ralph's default attack -- considering the victim is someone Ralph would actually attack.


So where does Bob figure in all this? What happens if Ralph attackes Bob? Or vice versa?
I agree that the instigator of the attack should be checked first and their script should check all othe NPCs that are present for their possible action/reaction.
If Ralph attacks Jane (which is against his principles) but you check her script as well as Bob's before performing Ralph's actions, and if Bob is scripted to help Jane, What happens?
Just trying to play Devil's Advocate here.


So where does Bob figure in all this?

That depends on where he is during any given turn, if he's even still in the game, if Jane has mistreated him, if Jane has flirted with him, if he has seen Jane flirt with Ralph, etc.

So, Bob may or may not be there, and he may or may not figure into anything at all if he is there, depending on what has happened in the story so far.

What happens if Ralph attackes Bob?

He may or may not wish to fight Ralph. Even if Ralph were to attack, Bob is skilled enough to bob and weave without really having to fight back to defend himself.

...but he might be mad at Ralph, or he might just be in a bad mood in general.

Or vice versa?

Ralph is the only NPC who obeys the player's command in this story. So, Bob would just tell you to bugger off if you were to say, "Bob, kick Ralph"

...but, if Bob were to take orders, it would work just like Ralph: Bob's attack script would have an if statement to handle being ordered to attack, which would be: "Violence will get us nowhere in this story," says Bob.


If Ralph attacks Jane (which is against his principles) but you check her script as well as Bob's before performing Ralph's actions, and if Bob is scripted to help Jane, What happens?

Ah! Good question!

Jane's attack verb script would have to call Bob's jane_under_attack script, which might just have to call Ralph's bob_jumps_in script. . .


I'm apparently making a Jerry Springer episode. :)


Ralph's attack attribute expects Ralph to be the attacker,
Every other NPC's attack script is just a verb

This is probably a bad idea. First off, it will put 'attack' on Ralph's verb list, which seems a little awkward. I think it would be better for Ralph's script attribute to be something like npcattack.

As for your question, I would handle it the same way as the "put" command.

If the attacker doesn't have a npcattack, they're not capable of attacking, so show a simple message. (Maybe with some other options. Like if npcattack is true, they'll attack anyone, and if it's a string, it could be a message like "Sorry, I'm a pacifist" that they respond with)

If there's an npcattack script, you rely on it to determine if they're willing to attack that person, and if so call the target's attack.

Actually, it probably makes sense to have a function PerformAttack (attacker, target), which is called by the npcattack script. The same function can be called from an attack command for cases where the player attacks directly.
This could handle a few cases:

  • target's attack is a script - run it, passing attacker (and weapon?) as a parameter
  • target's attack is a string - display the message
  • target's attack is true - use the default attack/damage calculation formula
  • target's attack is false or null - "You can't attack it"

So… when the player tells one NPC to attack another, it calls the attacker's npcattack script, and relies on that to call PerformAttack. When the player attacks directly, it just calls PerformAttack. Which then calls the target's attack.


That sounds quite logical.


I honestly got lost in my own example. :)

I should have went with a hang command. A garment can have a hang property, and a hanger can have a hang property.

...but your answer really fits any action which could be performed, which is one reason I value your input.


I should have went with a hang command. A garment can have a hang property, and a hanger can have a hang property.

In any case, it makes sense for an attribute to have a distinct meaning. If there's multiple things a word could mean, it probably isn't the best name for an attribute. For the hanger, you could have separate hangthisonsomething and hangsomethingonthis properties. That way, it's easy to check whether a certain action is valid for any given object, and there's no chance you'll put the script in the wrong place during later editing.

Same applies for homonyms, I think. If there's a word that could mean multiple things, pick a synonym for each that's clear and unambiguous. Then for a word with multiple meanings, you'd have a command which tests which of the meanings is valid for that object and calls the appropriate one (or possibly gives a disambiguation menu).


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums