AnssiR66 / AlanStdLib

The Standard Library for ALAN Interactive Fiction Language
Other
5 stars 2 forks source link

Potential Issues With NPCs Following Hero #118

Open tajmone opened 3 years ago

tajmone commented 3 years ago

To implement NPCs following the Hero, the library attaches a SCRIPT to each NPC, as can be seen in lib_actors.i:

ADD TO EVERY ACTOR
  ...

  INITIALIZE

    MAKE hero compliant. -- So the hero can give, drop, etc. carried objects.

    -- All NPC actors will obey this script from the start of the game:
    IF THIS <> hero
      THEN USE SCRIPT following_hero FOR THIS.
    END IF.

  SCRIPT following_hero
    -- ------------------------------------------------
    -- This code will make any NPC follow the hero,
    -- if the actor is given the attribute `following`.
    -- ------------------------------------------------
    STEP WAIT UNTIL hero NOT HERE
    ...
    USE SCRIPT following_hero FOR THIS.

The problem with this approach is that if the author attaches a custom SCRIPT to an actor, the following_hero SCRIPT would be interrupted and never resumed — I've searched the whole library and couldn't find any RULE or EVENT that takes care of resuming the following_hero SCRIPT by any means.

I haven't actually tested this, but it seems reasonable to assume so, since ALAN only allows one SCRIPT at the time for each actor.

Definitely, this is something worth mentioning in the documentation.

But a question remains unanswered: what happens if an NPC is running a custom SCRIPT and also set to following? It seams reasonable to presume that an actor won't be able to abide to the following_hero SCRIPT while executing a custom SCRIPT. This is a potential source of problems (and a design flaw), for authors would be expecting the following attribute to guarantee that the NPC follows the hero at all times — and, quite frankly, depriving them of the freedom to animate their characters via custom SCRIPTs, just for the sake of the following_hero feature, is too high a price to pay.

Probably the hero-following feature could be implemented another way, without resorting to SCRIPTs — maybe a RULE? — since the task boils down to relocating an NPC to the hero's location whenever the hero changes location.

Need to verify this, test it, and experiment with it.

AnssiR66 commented 3 years ago

Yes, well spotted. It is indeed so that an NPC can only execute one script at a time. If the author needs a more varied script for an NPC - both following and doing some other things at the same time, the author can choose between three things:

1) just use the 'following' script and describe the other actions of the NPC through descriptions:

THE npc ISA ACTOR IS following. HAS desc_value 1. DESCRIPTION IF desc_value OF npc = 1 THEN "The npc walks around the room and admires the antique furniture." ELSIF desc_value OF npc = 2 THEN "The npc takes a book from the shelf and leafs through some pages." ELSIF.... END IF. INCREASE desc_value OF npc.

  ...

END THE npc.

(of course adjusting the descriptions so that when the hero moves, the actions of the npc apply in the various rooms) (I didn't test this, so I didn't experiment in which order the "The npc follows you." and "The npc walks around the room..." descriptions are placed exactly, in relation to each other.)

2) use the 'following' script and describe the npc's other actions through events:

THE npc ISA ACTOR IS following. HAS value 1. END THE npc.

SCHEDULE npc_script AT hero AFTER 5. (-- or whenever)

EVENT npc_script. IF value OF npc = 1 THEN "The npc walks around the room and...." ELSIF value OF npc = 2 THEN "The npc takes a book ...." ELSIF.... END IF. INCREASE value OF npc. END IF.

3) just make a wholly individual script for the npc, without making it 'following'.

THE npc ISA ACTOR SCRIPT STEP IF hero NOT here THEN LOCATE npc AT hero. "The npc walks around..." STEP IF hero NOT here THEN LOCATE npc AT hero. "The npc takes a book..." STEP IF hero NOT here... END SCRIPT. END THE.

(Thinking about this quickly, I think the "if hero not here..." must be repeated at every step separately, like above. If we use "WAIT UNTIL hero NOT here", then the npc never does anything until the hero leaves.

If this was helpful, you can copy the above (and edit it if you wish), to the appropriate passage in the manual.

tajmone commented 3 years ago

Indeed, it was helpful. I'm sure that mentioning this issue in the StdLib Manual should be a good start, if not enough as a solution — after all, if an author is capable of creating a complex custom actor script, he/she'll also be able to ensure that when his script end he restarts the follow-hero script.

It's really more of a problem of lacking documentation (in both sources and Manual) then a bug or a design flaw. I mean, we can't really do much about the fact that ALAN only allows one script at the time for each actor. The problem here is that we need to make it clear that there's this limit — if not, then it become a design flaw for the simple reason that it breaks a promised feature. Mentioning the caveat that comes with it is sufficient.