Scripted Actions for Characters other than the player

I want to fill a town with people but I have only some idea how to do it. After some trying around with the Odyssey example code and some help from others here is the code so far:

Table of Athena’s Movement
origin destination chance to move
Thebes Delphi 25
Delphi Thebes 99
Thebes Athens 50
Athens Corinth 25
Corinth Mycenae 25
Mycenae Thebes 30

Every turn when Athena is active:
let last space be the location of Athena;
choose row with an origin of the location of Athena in the Table of Athena’s Movement;

if a random number from 1 to 100 is less than the chance to move entry:
    if Athena can be seen by the player, say "Athena heads to [the destination entry].";
    move Athena to destination entry;
    if Athena can be seen by the player, say "Athena arrives from [the last space].";

The idea is that people stay for a random amount of time in one room before moving ahead. But for some the random number part won’t compile properly because I haven’t initialised the chance part of the table.

Is here someone who can help me with my problem?

Do you have a blank line in between these two lines?

[code]
choose row with an origin of the location of Athena in the Table of Athena’s Movement;

if a random number from 1 to 100 is less than the chance to move entry:[/code]

The blank line is treated as the end of a code block, so Inform doesn’t realize that “if a random number…” is supposed to be part of the same rule.

One thing that’s helpful here is to paste your code in code tags (hit the “code” button above the window where you type your message). That way you can be sure the indentation and spacing is properly preserved, which can be important.

Creating a lot of generic NPCs and moving them all around is possible. I’ve certainly done it.

One thing to consider is how interactive you want your villagers. If you just want your scenes to appear busy, it’s much easier to write randomized atmosphere messages with a backdrop object.

Depending on the size of your game and what you’re going for, you might not want the overhead of moving 20 NPCs constantly where the player won’t even notice it. You might want to just “activate” the NPCs the player can see and perhaps those in adjacent locations. One suggestion is run through your nearby villagers and give them a random chance to move. When one moves, you stop checking. That will avoid spamming arrival and departure messages since only one will move at a time. Or, create one varying group of NPCs that subtly follow the player around (think how a movie production saves money and hassle by re-dressing the same five actors and arranging them in the background of the shot repeatedly from different angles instead of employing 100 extras who just fill space that’s out of frame.)

You can certainly populate a town with people and give them routes, but route-finding is one of the things that really can slow the parser down.

I’m not trying to discourage you, but consider that one of the magic things about IF is that it is possible to save yourself hours of implementation and coding by intelligently managing simulation vs. narration. You can give the player the impression a lot is going on with clever writing - which takes a lot less time than implementing and troubleshooting a hundred intricate moving parts that aren’t critical to the story you’re telling. Often the more optimal player experience is when the author subtly pushes story elements in front of the PC rather than making the player chase them down. Just make sure the work you do is in service to something actually fun and interesting for the player and the story rather than busywork for you that may go unnoticed.

TL;DR - You can implement a toothbrush with bristles which are a supporter and a toothpaste tube container with an unscrewable cap that’s another piece and manage the amount of volumetric liquid paste in the tube and have the player SQUEEZE PASTE ON BRISTLES and then INSERT BRUSH IN MOUTH, BRUSH UP, BRUSH DOWN, BRUSH UP, G G…
…or you can just mention to the player they brushed their teeth as part of the room description.

Thanks for the quick feedback! My game is an assignment for a university course. My main character has to be able to talk to the villagers and recruit three of them to perform a task in the next scene. Each villager is supposed to walk between the rooms, enter shops and carry something back to their house. So at least for me the easy but elegant way out like in your toothbrush example won’t work for me.

What, they won’t let you just say “…and then everyone did their grocery shopping and returned home.” ?

Darnit. :laughing:

Fair enough! It’s a good exercise at least.

See the recipe book on travelling characters. It will probably help a lot.

http://inform7.com/learn/man/RB_7_13.html

[rant=random ideas]I’d make your shopping district a continuous square of four locations (open air shops). Give your villagers a “shopped” truth state. When it’s false, they navigate the ring in one direction or the other each turn. If they’re next to the correct shop, there’s a random chance they will purchase the item they want and flip “shopped” to true. When shopped = true, they instead navigate to their home and shut down. At any time the player can talk to them to recruit.

A line of code that has helped me a lot is:

Definition: a direction (called thataway) is viable if the room thataway from the location is a room.

Modify it to:

Definition: a direction (called thataway) is Fredviable if the room thataway from the location of Fred is a room.
Then (i think) you can ask NPC Fred to go “a random Fredviable direction”.

Then:

A person has a room called homeroom. The homeroom of Fred is quaint thatched dwelling. Every turn when shopped of Fred is false: if the location of Fred is not homeroom of Fred: try Fred going the best route from the location of Fred to the homeroom of Fred.[/rant]

If you knew how often I was about to do something like this but somebody else reminded my that it is supposed to be a game and not a book. :laughing:

Thanks for the reply. I have been to the book about traveling characters but it didn’t really help me, except for the idea with the table from the Odyssey-Code. At this point your solution seems to be smoother. I will try it when I’m home and tell you how it went.

You can even do this with a relation, so you don’t need a different definition for everyone:

[code]Viability relates a direction (called thataway) to a person (called the goer) when the room thataway from the location of the goer is a room. The verb to be viable for means the viability relation.

A person can be stationary or wandering. A person is usually stationary.

Every turn:
repeat with subject running through wandering persons:
try the subject going a random direction that is viable for the subject.

Kansas is a room. Alaska is north of Kansas. San Francisco is west of Kansas. Honololu is west of San Francisco. Oslo is east of Alaska. Paris is south of Alaska and east of Kansas.

Jane is a wandering woman in Kansas. Bob is a wandering man in Kansas.[/code]

(In real code, it’s better to do a safety check that there is a direction that’s viable for the subject before you try to pick a random one, or you can hit run-time errors when there’s no such direction… but in this map, there’s always a viable direction.)