intfiction.org

The Interactive Fiction Community Forum
It is currently Tue May 21, 2013 5:06 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: NPC wait to attack error
PostPosted: Sat Jun 30, 2012 9:00 pm 
Offline

Joined: Thu Jun 28, 2012 3:55 am
Posts: 9
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."

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


Top
 Profile Send private message  
 
PostPosted: Sun Jul 01, 2012 8:48 am 
Offline

Joined: Sun Dec 05, 2010 11:07 am
Posts: 321
Location: ኢትዮጵያ
fuzzinator1234 wrote:
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."

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:

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


Top
 Profile Send private message  
 
PostPosted: Sun Jul 01, 2012 9:26 am 
Offline
User avatar

Joined: Thu Nov 04, 2010 6:30 am
Posts: 985
Location: Gothenburg, Sweden
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!".

_________________
Man ska inte tro allt man tänker.


Top
 Profile Send private message  
 
PostPosted: Sun Jul 01, 2012 9:36 am 
Offline

Joined: Wed Feb 29, 2012 2:00 pm
Posts: 672
Felix wrote:
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!".



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.

_________________
"Will you stop breaking the fourth wall? It's costing me an absolute fortune to replace it!"


Top
 Profile Send private message  
 
PostPosted: Sun Jul 01, 2012 9:57 am 
Offline
User avatar

Joined: Sat May 08, 2010 9:25 pm
Posts: 959
Location: The Seattle Massive
climbingstars wrote:
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.)


Top
 Profile Send private message  
 
PostPosted: Sun Jul 01, 2012 10:42 am 
Offline

Joined: Wed Feb 29, 2012 2:00 pm
Posts: 672
maga wrote:
climbingstars wrote:
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?

_________________
"Will you stop breaking the fourth wall? It's costing me an absolute fortune to replace it!"


Top
 Profile Send private message  
 
PostPosted: Sun Jul 01, 2012 12:53 pm 
Offline

Joined: Thu Jun 28, 2012 3:55 am
Posts: 9
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!".

but instead of working it just says "One of the walkers turns towards you, moaning." every turn instead of attacking


Top
 Profile Send private message  
 
PostPosted: Sun Jul 01, 2012 2:23 pm 
Offline
User avatar

Joined: Thu Nov 04, 2010 6:30 am
Posts: 985
Location: Gothenburg, Sweden
It works fine with me. Here's a guess why it might not work for you.
Perhaps you have defined the properties like this:
Code:
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:
Code:
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
Code:
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).

_________________
Man ska inte tro allt man tänker.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: R2T1 and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group