Consolidating "instead" rules for low-impact scenery

So I have code like this, but for 200-300 things, mostly scenery. (Hey! You in the back! Stop giggling!) As I understand, this might cut down compile time and, possibly, pause between moves fpr the user. (A small pause currently exists in the game. It’s A Roiling Original, if you’re curious.)

Plus, the organization would be useful to help me find obvious narrative bugs. But it’s a big enough change I wanted to check off with anyone willing to give helpful pointers where I may’ve missed a small adjustment that could have a big impact.

definition: an action (called ac) is procedural: [not part of the changed code, but just for reference]
	if examining, yes;
	if object-hinting, yes;
	if taking, yes;
	no; [there can be more. In fact there are in my code. I just want to establish that a procedural activity is something we should not generically reject. It's handy for time-based puzzles where certain obvious actions that don't take a minute in real life, shouldn't in the game.]

mountain-scenery is scenery. wire-scenery is scenery.

instead of doing something with wire-scenery:
	if action is procedural, continue the action;
	say "The wire has no special properties other than to keep you going south."

instead of doing something with mountain-scenery:
	if action is procedural, continue the action;
	if current action is climbing or current action is entering, try going west instead;
	say "The mountain isn't particularly remarkable except for being too big to let you go west."

I’d love to cut this down, and normally I wouldn’t ask a question like this … but planning changes to 200-300 rules is a lot, so I wanted to see 1) if this was sensible and 2) if there were any details beforehand, so I wouldn’t be in a position to need/want to make potentially 200-300 changes, big or small, later. It just feels like I’m spinning a couple plates doing this–but also, if it works, I think it might be something worth sharing with less experienced programmers.

Below is uncompiled code, but I just wanted to get a big-picture view: is there anything I should add or tweak to my code-twiddling plans?

bound-scen is a kind of scenery. bound-scen has text called bound-text. bound-scen has a rule called bound-rule.

mountain-scenery is scenery. bound-text is "The mountain isn't particularly remarkable except for being too big to let you go west." bound-rule is mountain-scenery-bound rule.

this is the mountain-scenery-bound rule:
	if current action is climbing or current action is entering, try going west instead;

wire-scenery is scenery. bound-text is "The wire has no special properties other than to keep you going south."

instead of doing something with bound-scen:
	abide by the bound-rule rule of noun; [the default will be an empty rule that does nothing]
	say "[bound-text of the noun]"

Thanks for any help, and I hope this may help other people in some way.

On a related note, I have a lot of small questions like these & don’t want to throw them out too often, but on the other hand, I do think they could be useful for beginners to say “Hey, I didn’t quite realize you could even -consider- things like that.” Especially since the questions I ask generally discuss things I didn’t see were possible, or I assumed they were too complex, when I started. Is there a good place for these on the forum, and if so, do they need a special subforum or tags?

1 Like

Can you make all the objects a new subkind? That would be both simpler to program as well as more performant.

Oh, I see that’s what your second code block is doing. Yes, that’s the approach I’d take.

1 Like

The following is not a rhetorical question.

Is there much/any difference between defining the actions with a ‘definition phrase’ vs doing it like below?

examining is acting procedurally.
object-hinting is acting procedurally.

and then,

instead of doing something with wire-scenery:
	if acting procedurally, continue the action;
	say "The wire has no special properties other than to keep you going south."

I ask as I’m doing basically same thing aschultz is doing in his whole post, I’m just phrasing it the way I phrased it in my quoted bits.

-Wade

1 Like

Yeah that’s a neater version of the original unoptimised code. And I think you can go further doing something like this (untested):

instead of acting procedurally when the noun is wire-scenery:
	say "The wire has no special properties other than to keep you going south."

But it has the same performance issues as the original. If you’re doing this with hundreds of objects, and therefore have hundreds of rules, then it will test each rule every command. By using a subkind and making the response text a property of the objects then only one rule is needed, and finding the appropriate text is a fixed property lookup rather than running through a long section of if-else code.

Well, the following is the approach I’ve been taking, designed to reduce the number of instead rules I’m using, but still make writing easy/flexible enough. I assume the performance is halfway inbetween the best and worst, or better, and infinitely better than when I had an instead rule for every object!

So when it will pay off, I group things into subkinds.

e.g.

a mountain-element is a kind of thing. a mountain-element is usually scenery.

Instead of doing anything other than examining to a mountain-element:
 yada yada

This leaves the description property to do the description work, which is the thing that will be different in every single case. But other action responses will vary sometimes, or a lot.

This instead rule is checked every turn, but then is passed over in every case we’re not dealing with mountain scenery, which to my eyes is a decent performance saving.

If the noun is mountain scenery, I do enter an if-then list in the instead rule, which is still only as long as the number of mountain sceneries.

-Wade

1 Like

I’d forgotten about

examining is acting procedurally.
object-hinting is acting procedurally.

I’d used it before and forgot why I stopped, but if it’s a bit faster, why not?

For Ailihphilia, I had a line with

	if useoning: [USE X ON Y]
		if noun is radar or second noun is radar, yes;

But I suppose this could be redone as “useoning radar with” and “useoning with radar.”

This also opens up the useful (to me) possibility of a sub-sub-kind.

semi-tinkerable-scenery is a kind of scenery

untinkerable-scenery is a kind of semi-tinkerable-scenery.

The untinkerable scenery would allow even fewer commands than the semi-tinkerable.

This seems like a step up from where in Ailihphilia (again) I defined

a thing can be peripheral, semiperipheral or integral. a thing is usually integral.
[ semiperipheral allows for USE X ON Y.
For instance, the player may try to use something on the Tru Hurt, which is reasonable and for which I tried to give amusing responses.
But using anything on the mush sum, described as totally impassable and clearly just blocking the way north, wouldn't.]

So thanks both of you for the discussion. It helped me with my question and then some.