NPC wait to attack error

i am trying to make it so that upon entering a room a zombie can see the player, and one turn later (giving the player a chance to strike first) the zombie attacks. i tried doing so with this code:

[code]Every turn when a walker is surprised:
If a walker can see the player:
say “One of the walkers turns towards you, moaning.’”;
now all walkers that can see the player are ready;
Otherwise:
Do nothing.

At the time when a walker is ready:
If a walker can see the player,
the walker attacks the player in one turn from now.

At the time when a walker attacks:
if a walker can see the player:
try attacking the player with walkerzombie-fists;
otherwise:
say “The walker looks around confused and then just stands there.”[/code]
but every time i do i get this error:

Problem. In the sentence ‘If a walker can see the player, the walker attacks the player in one turn from now’ , I was expecting to read a rule, but instead found some text that I couldn’t understand - ‘walker attacks the player’.

I was trying to match one of these phrases:

  1. (walker attacks the player - rule) in (one - number) turn/turns from now

  2. (walker attacks the player - rule) in (one turn - time) from now

This was what I found out:

walker attacks the player = something unrecognised

one turn = something unrecognised

You called a timed event “the walker attacks the player”, but defined it as “a walker attacks”. Those two names have to match.

Also, you define another, “a walker is ready”, but never call it. You probably want to use an every turn rule, instead:

Every turn when a walker is ready: If a walker can see the player, the walker attacks the player in one turn from now.

Another way would be to let the walkers pass through three property stages (surprised, ready, and violent) rather than just two (surprised and ready).

I think this gives the wanted effect. Note that the order of the last two every turn rules is crucial!

[code]The Place is a room.
The Crypt is north of the place.
A walker is a kind of person.
A walker can be surprised, ready or violent.
Three walkers are in the crypt.

Every turn when a walker (called Mr Hyde) is surprised:
if Mr Hyde can see the player:
say “One of the walkers turns towards you, moaning.”;
now all walkers that can see the player are ready.

Every turn:
repeat with Mr Hyde running through walkers that are violent:
if Mr Hyde can see the player, try Mr Hyde attacking the player.

Every turn:
repeat with Mr Hyde running through walkers that are ready:
if Mr Hyde can see the player, now Mr Hyde is violent.

Instead of someone attacking the player: say “[The actor] attacks you! Aargh!”.[/code]

Does the “Mr Hyde” variable survive through to the last two every turn rules? I would have thought that it would be out of scope by that point.

No; it gets defined anew each time. (For readability, it’s often convenient to use the same name for different local variables if they will, in practice, always be the same sort of thing.)

Of course! The repeat redefines the variable. How did I miss that?

I tried using

[code]Every turn when a walker (called Mr Hyde) is surprised:
if Mr Hyde can see the player:
say “One of the walkers turns towards you, moaning.”;
now all walkers that can see the player are ready.

Every turn:
repeat with Mr Hyde running through walkers that are violent:
if Mr Hyde can see the player, try Mr Hyde attacking the player.

Every turn:
repeat with Mr Hyde running through walkers that are ready:
if Mr Hyde can see the player, now Mr Hyde is violent.

Instead of someone attacking the player: say “[The actor] attacks you! Aargh!”.[/code]
but instead of working it just says “One of the walkers turns towards you, moaning.” every turn instead of attacking

It works fine with me. Here’s a guess why it might not work for you.
Perhaps you have defined the properties like this:

A walker is a kind of person. A walker can be surprised. A walker is usually surprised. A walker can be ready or violent.
instead of like this:

A walker is a kind of person. A walker can be surprised, ready or violent.

If so, being surprised will be independent of being ready or violent, which means that, when the first every turn rule makes the walkers ready, they remain surprised as well. Since they are now ready (rather than violent), the second every turn rule doesn’t take effect; but the third one does and (during the same turn) makes them violent rather than ready (all the while they remain surprised).
Then at the end of the next turn, since they are still surprised, the first every turn rule again makes them ready rather than violent! And so the second every turn rule won’t take effect this turn either.

In contrast

A walker can be surprised, ready or violent.

will make the three named values incompatible with each other (so that, when a walker gets ready, it ceases to be either surprised or violent).