Intercepting certain actions

I’m trying to work around a run-time problem resulting in “The memory stack is exhausted (P46).” The offending code:

	if resistanceIsUseless is TRUE:
		instead:
			say "some stuff...";
			brainwash the player.

My intent: When a game condition occurs, certain actions (in this case any movement - n,s,e,w) initiated by the player will trigger a host of actions instead. I tried setting up a scene, but I think I7 is unhappy with imbedding instead as for example in:

	if resistanceIsUseless is TRUE:
		say "can't move now";
		decide yes;
	otherwise:
		decide no.
Frozen is a scene.
Frozen begins when the player cannot move.
When Frozen begins:
	first check the player going:
		instead:
			say "stuff...:;
			brainwash the player.

Am I taking I7 beyond its capability or is there way to accomplish this?

To trigger actions when “going” (the verb used to indicate movement) you want something like this:

The Lab is a room. The garden is north of the Lab.

Instead of going north from the Lab:
    say "The mad scientist prevents you from going that way.";

This won’t work unless there’s an exit to the north. Otherwise:

Instead of going north from the Lab:
    if the noun is north:
        say "The mad scientist prevents you from going that way.";
2 Likes

instead has two different uses with enough in common that they’re easy to confuse. It’s the name of a rulebook. Where you see lines beginning Instead and ending with a colon, those are specifying new rules to be listed in the Instead rules.

Instead of eating the apple: say “but you hate apples.”

(A special syntax allowed for Before, Instead, and After is that if the rule is just one line, you can use a comma instead of a colon.)

instead can also be followed by a phrase and that means: perform this phrase, and then stop the action. So it’s generally only used in Before or Check rules.

4 Likes

I’ve had to push pretty hard to take I7 beyond its capabilities. There are limitations imposed by the parser design, and limitations in the presentation layer (which have to do with the Z-Machine and Glulx really, not the language itself), but most things you can think of are possible.

1 Like

Explicitly referencing the location was something I did first just to get some running code, but what I need is for this condition to operate from all possible rooms that could be inhabited by the player. That seems too much for I7 to handle, at least with the code I tried.

What’s the code you tried?

I simplified it to narrow it down to this:

To decide whether the player cannot move:
	if (resistanceIsUseless is TRUE), decide yes;
	decide no.

Frozen is a scene.
Frozen begins when the player cannot move.
When Frozen begins:
	say "test";
	instead the player going:
	say "got to this point".

The instead rule fires no matter what the condition is (tried setting the variable to FALSE as well). The output is always:

>go w
got to this point
>go s
got to this point
>go w
got to this point

Strangely, the statement: say "test"; is always skipped. That leads me to believe that when such rules are defined, they ignore the surrounding context when they fire.

This is what blows up I7 with the Run-Time Problem discussed above:

first check the player going:
	if resistanceIsUseless is TRUE:
		instead:
			say "something";
			brainwash the player.	

That’s because, despite the way you have it formatted, these:

… are two different rules: a “When Frozen begins” rule (which never fires) and an “Instead of going” rule which would fire during any scene.

1 Like

Your stripped-down example works fine tweaked:

Lab is room.

resistanceIsUseless is a truth state which varies.

After jumping:
	now resistanceIsUseless is true.
	
To decide whether the player cannot move:
	if (resistanceIsUseless is TRUE), decide yes;
	decide no.

Frozen is a scene.
Frozen begins when the player cannot move.
When Frozen begins:
	say "Test successful. Frozen begins.".
	
Instead of going during frozen:
	say "got to this point.".

Test me with "s / jump / s".
2 Likes

Ah the magic word is

	during

Thank you! Not directly related to original post, but for those observing: As I was fishing through the documentation just now, I found a reference to another useful magic word - “recurring” as in:

Frozen is a recurring scene.

This solves a number of confounding difficulties I’m having with scenes. Yes, yes, scene is a cool shiny new tool for me that I may be overusing… :slight_smile:

1 Like