Travel cost and action cost

Hello there everyone. I have been mucking about with Inform 7 but I am still struggling because I think too much like a programmer. I know TADS 3 exists which I actually tried but its standard library is too much of a mess to use and I actually like the literary approach Inform 7 takes.

To get to my question, what I like to do is the following:
Every room and ideally every action should have a time cost involved. For the room each time the player enters a room the travel cost of said room should be the time in minutes the time advances. The travel cost ideally should be a mandatory “field” or “property” of the room class basically with a type of minutes since that seems to be built in. Ideally the compiler should yell at you if a room does not have that value instead of applying a default but if that is too complicated I am okay with it having a default.

For the actions I would want something similar. I want to be able to define a action cost for each action that is a mandatory field or property of that action and if that action is taken (no matter if it suceeds or or not) the action cost is added to the current time.

Ideally I could define a actiongood and actionbad cost different but that would just be the icing on the cake. I tried several things rummaged through the documentation but the verbage escapes me and I did not get it to work or even compile it to any working code and am on the verge of giving up.

Any help would be greatly appreciated.

1 Like

By default, every action (successful or not, other than entirely failed parses or mistakes) costs 1 turn or 1 minute (though the relationship of turns to minutes can be customised with extensions).

But that’s just the default system. You can define your own extra variable to keep track of time completely independently from the built-in system easily enough (though you may want to still use the built-in one if you want to make use of timed events).

There’s a whole chapter on time if you want to read up on the standard system.

It’s 1am for me right now so it’s a bit late in the day for me to offer specific code examples for your other questions, but I’m sure someone will beat me to it anyway. :grin:

Thank you for taking time to reply. I did read the documentation and some of the cookbook examples but am sadly still stumped. You hit the nail on the head on what I am struggling with there. Its primarily implementation I have a clear design goal but no hecking clue on how to even approach the problem, so I hope someone here can help me out with a code example.

I do not intend to take that example 1:1 but want to fundamentally understand how this works so I struggle less in the future with inplementing custom mechanics. For example I have no clue where to look to see the standard rule for time or how to modify it as I think I said above. In Tads3 I could look for the corresponding class but where would I look in Inform 7?

Apologies if this is too basic, but sounds like you’re looking for the building blocks so you can get into the hard stuff – as mentioned in the section of the documentation Gavin linked to (9.6), the main way Inform tracks time is through a variable called “the time of day.” The section shows you how to directly change it, but it’s also easy to change it via the regular rules that apply to actions, like before rules for example:

Before jumping:
	Now the time of day is the time of day plus one minute.

(Note that actions take one turn/minute by default, so this would actually advance the clock by two minutes).

Those are the basics – obviously it gets very complicated from there! One thing I’d flag based on your initial post, though, is that I think conceptualizing this as adding a time cost to actions and to rooms might be confusing and you should really just think about it in terms of actions. Rooms might take more or less time to get to depending on the exit/entrance used, and you can capture that with rules apply to specific instances of the going action.

Hope this is helpful!

@MikeRusso I appreciate what you are trying to do but what you suggest is not what I need in the slightest. If it were just that I would not be needing help. What I look for is specifically what I asked for in that I need a generalized system explicitly not to having to re define it constantly.

What I am looking for is a generalized approach for when the player enters a room, which is the use case I have at hand.

The mechanisms you describe can all be easily powered by the extension Variable Time Control, by Eric Eve. Have a look for it in the Public Library section of the Inform IDE, or whatever the equivalent is for PCs if you’re not on a Mac (sorry, I don’t know how it works on PCs. Or maybe it’s there now and I don’t know that it is!)

The documentation with the extension is pretty good, but to get you going on how to give rooms a time value, you can do something like the following:

A room has a number called travel-cost. [We'll measure this in seconds.]

The travel-cost of a room is usually 60. [This demonstrates how to set
the default cost for a room. So I set it to be 60 seconds.]

Now say you’ve got a room called Laboratory that you want to have a non-default cost, you can say in the source:

The travel-cost of Laboratory is 30.

Then you need to add a function that applies the travel-cost whenever the player goes to a new location. Working out where/how to put this rule required me looking at the ‘actor going’ rules in the Standard Rules extension and copying/cannibalising one a bit. You were saying you wonder where to look for info on some mechanics; that extension is often the place. The ‘say N seconds’ expression comes from the Variable Time extension and I should point it causes that many seconds to be taken using the extension’s time mechanism.

Last carry out an actor going (this is the apply travel-cost for player movement rule):
	if the actor is the player or the player is within the vehicle gone by or the player is within the thing gone with:
		say (travel-cost of the location) seconds;

I typed this on the fly and haven’t tested it, but I hope it’s not buggy. This might be enough for you. If it’s not, I’ll let someone else chime in.

-Wade

@severedhand thank you very much this is pretty much what I am looking for, I give this a whirl. I was hoping to be able to do this without an extension but if this works I gladly use it, thank you so much!

Cool. I should point out I made a few tiny edits to the post while you were replying. Two were just sort of advice lines, and one was a missing colon in that ‘carry out going’ rule that I wrote.

-Wade

(Note to self, since I don’t have time to make a full example rn: suggest a rulebook for the action costs)

Perhaps you could associate time costs with actions using a table. Something like

This is the new advance time rule:
	increment the turn count;
	increase the time of day by the action time.

The new advance time rule is listed instead of the advance time rule in the turn sequence rules.

To decide what time is the action time:
    let A be the action name part of the current action;
	if A is an action name listed in the Table of Action Times:
		let T be the time entry;
		decide on T minutes;
	decide on 1 minute.

Table of Action Times
Action name	              Time
Taking action	            2
Removing it from action	3
Jumping action 	        6
Examining action	        0	

It would be easy enough to associate a “good” and "bad time with each action, by adding an extra column, and modifying the “to” rule appropriately.