Storing actions per character

Related to my previous topic (working distance and speed into going actions), I’ve decided to overhaul Eric Eve’s Variable Time Control to allow for even more ridiculous levels of micromanagement. That’s just the kind of coder I am. Basically, what I want (also see flowchart below) would be to run through the first time, add the delay, get out, wait for my while loop to reach the specified period, and restart the action with a toggle indicating that the normal progression should occur. The easiest way I see to do this would be to store the action when the first delay is added and call it again after the wait ends. Unfortunately, I want to allow this for NPC characters as well, so the action would have to be stored as a property of a person, and it doesn’t seem like actions are an accepted kind of value in that situation. Is there any way to do this, or will I have to come up with some other method?

[code] ┌─────→ Input
│ ↓
Wait Check ←─*── Wait
↑ ↓ ↑
│ Lead-in ─→ Add time
│ ²↓ ¹
Add time Carry out
↑ ↓
└───── Recovery

  • Leading back to the check ensures
    continued legality if world changes.[/code]

This line compiles for me, though I didn’t do anything with it; is there another problem you’re encountering with using it?

Every person has a stored action called the pending action.

Yeah, that does it. I somehow missed that section of the docs and wasn’t adding the “stored” part of the name. Sorry for bothering you needlessly!

All right, it’s decided to stop working again, this time by (apparently) entering an infinite loop. What I have runs the first turn perfectly, takes the object (testing with that verb), prints the name of the room again, then freezes. It also does not increase the time. What makes this all the more annoying is that it was working not that long ago, but I made some small tweak and was worse off than I had been for a while. I no longer remember what the change was, and the various taskkills have not been to good for my undo history. Can any of you spot what’s causing this?

[code]The seconds are a number that varies. The seconds are 0.

Every person has a stored action called the pending action.
Every person has a number called the wait timer.
Every person has a truth state called the preparation toggle.

This is the time progression rule:
while the wait timer of the player is not 0 or the preparation toggle of the player is not false:
repeat with the character considered running through people:
unless the wait timer of the character considered is 0:
decrement the wait timer of the character considered;
if the wait timer of the character considered is 0:
if the preparation toggle of the character considered is true:
now the preparation toggle of the character considered is false;
try the pending action of the character considered;
now the pending action of the character considered is the action of waiting;
increment the seconds;
if the seconds are 60:
now the seconds are 0;
increment the time of day;
abide by the timed events rule.
The time progression rule is listed instead of the advance time rule in the turn sequence rules.
The timed events rule is not listed in the turn sequence rules.

The prepare rules are a rulebook in the specific action-processing rulebook.
A specific action-processing rule (this is the prepare stage rule):
if the preparation toggle of the actor is false:
now the preparation toggle of the actor is true;
now the pending action of the actor is the current action;
abide by the prepare rules.
The prepare stage rule is listed before the carry out stage rule in the specific action-processing rulebook.[/code]

After the time progression rule sets the preparation toggle to false, it tries the pending action. But before the pending action is carried out the prepare stage rule runs, and it resets the preparation toggle to true, which means the conditions of the while loop in the time progressions rule is met anew, ad infinitum.

Ah. I knew there was a reason I put the reset in the prepare stage when I first wrote it. Thanks for pointing that out!

EDIT: Just to head off the possible advice, I know that it works just as well after the call to the action. That’s where it is now.

Sorry for the double posting, but this should be the last question I have in this thread. As part of the time advancement stage, I want to provide a weak hook for including AI. Using a rulebook, I have created what I believe will do nothing by default, while still allowing easy access to that feature (see below again). It should work, except for filling in the actor. Is there any way to access the (in this case) person that an object-based rulebook is working on? Essentially, I want to find some analogue of “actor” (though, as I understand it, that’s a rulebook variable, not a subject) so I can write something similar to “rule succeeds with result the action of the actor waiting.”

[code]This is the time progression rule:
while the wait timer of the player is not 0 or the pending action of the player is not the action of waiting:
[irrelevant]
repeat with the character considered running through people who are not the player:
[irrelevant]
if the wait timer of the character considered is 0 and the pending action of the character considered is waiting:
let the chosen action be the stored action produced by the action selection rules for the character considered;
if the chosen action is not waiting:
try the chosen action.

The action selection rules are a person based rulebook producing a stored action.
A action selection rule (this is the default action selection rule):
rule succeeds with result the action of waiting.[/code]

I think it’s as simple as this.

Action selection someone (called John Doe) (this is the default action selection rule):
	rule succeeds with result the action of John Doe waiting.

That looks like it works. Now, though, I’m getting an error in a related location (different rulebook, but same structure). The line is in a “setting action variables” rule for going—and appears in the right location in the index—which should give it access to the actor. Unfortunately, that’s what Inform’s complaining about. If I include “for the actor”, it tells me it can’t recognise the last two words. If I take them off, it says that the going speed selection rules are people-based and I need someone to apply it to (“for the player” works perfectly, but is not general enough).

Rule for setting action variables for going (this is the timed set going variables rule): now the speed gone at is the number produced by the going speed selection rules for the actor; [continued]

I think you need to include “the actor” in the name of the rule as well, to tell Inform that it needs to apply to any actor attempting to go, not just the play.

At least, this minimal source compiles and runs for me:

[code]There is room.

The going action has a number called the speed gone at.

Rule for setting action variables for an actor going (this is the timed set going variables rule):
now the speed gone at is the number produced by the going speed selection rules for the actor;
showme the speed gone at;
[continued]

The going speed selection rules are a people based rulebook producing numbers.

A going speed selection rule:
rule succeeds with result 1.[/code]

I think I tried that before, but after double checking, it still gives me an error. And since everything goes through if I replace that one word, I’m not sure what’s going on. Looking at the debug log, I get a “Problem C24BadOptionalAPClause”, but that doesn’t seem to explain much.

[code]Rule for setting action variables for an actor going (this is the timed set going variables rule):
now the speed gone at is the number produced by the going speed selection rules for the actor;
unless the redirect speed is 0:
now the speed gone at is the redirect speed;
now the redirect speed is 0;
unless the redirect scale is 1:
now the speed gone at is the speed gone at multiplied by the redirect scale;
now the redirect scale is 1;
now the first distance gone over is the default distance;
now the second distance gone over is the default distance;
repeat through the Table of Room Distances:
if the start entry is the room gone from and the end entry is the room gone to:
if there is a first entry, now the first distance gone over is the first entry;
if there is a second entry, now the second distance gone over is the second entry;
otherwise if the end entry is the room gone from and the start entry is the room gone to:
if there is a second entry, now the first distance gone over is the second entry;
if there is a first entry, now the second distance gone over is the first entry;
now the total distance gone over is the first distance gone over plus the second distance gone over;
now the time gone for is the total distance gone over multiplied by the speed gone at.

The going speed selection rules are a person based rulebook producing a number.
A going speed selection rule when someone (called the subject) is in an enterable vehicle (this is the default carriage speed rule):
rule succeeds with result 15.
A going speed selection rule (this is the default going speed rule):
rule succeeds with result 30.
The default going speed rule is listed last in the going speed selection rules.
[/code]

Hmm, I can’t reproduce that error. At best I get variable unrecognized errors if I don’t define them at the start, but this code compiles fine for me:

[code]There is room.

The going action has a number called the speed gone at.
The going action has a number called the redirect speed.
The going action has a number called the redirect scale.
The going action has a number called the first distance gone over.
The going action has a number called the second distance gone over.
The going action has a number called the total distance gone over.
The going action has a number called the time gone for.

The default distance is a number that varies.

Table of Room Distances
start first second end
(a room) (a number) (a number) (a room)

Rule for setting action variables for an actor going (this is the timed set going variables rule):
now the speed gone at is the number produced by the going speed selection rules for the actor;
unless the redirect speed is 0:
now the speed gone at is the redirect speed;
now the redirect speed is 0;
unless the redirect scale is 1:
now the speed gone at is the speed gone at multiplied by the redirect scale;
now the redirect scale is 1;
now the first distance gone over is the default distance;
now the second distance gone over is the default distance;
repeat through the Table of Room Distances:
if the start entry is the room gone from and the end entry is the room gone to:
if there is a first entry, now the first distance gone over is the first entry;
if there is a second entry, now the second distance gone over is the second entry;
otherwise if the end entry is the room gone from and the start entry is the room gone to:
if there is a second entry, now the first distance gone over is the second entry;
if there is a first entry, now the second distance gone over is the first entry;
now the total distance gone over is the first distance gone over plus the second distance gone over;
now the time gone for is the total distance gone over multiplied by the speed gone at.

The going speed selection rules are a person based rulebook producing a number.

A going speed selection rule when someone (called the subject) is in an enterable vehicle (this is the default carriage speed rule):
rule succeeds with result 15.
The last going speed selection rule (this is the default going speed rule):
rule succeeds with result 30.[/code]

Yeah, I just tried isolating it myself, and it worked. So there must be a problem somewhere else in the code. Well, time to comment stuff out until I find it!

EDIT: Well, that was an interesting mistake. I had matched the time gone for as “for”. No wonder Inform was getting confused! Thanks for giving me the working recode, though. It allowed me to compare blocks more directly.