Two devices, one reliant on the other for power, with conditions

Hi,

I have two devices that can be turned on. The chart plotter can only be switched on when the breaker board is switched on.

If the chart plotter is examined before the breaker is switched on, it says ‘The chart plotter is off’.

After switching on the chart plotter but before the breaker is switched on, it says ‘There is no power to the chart plotter.’.

If the breaker board is switched on, but before the chart plotter is switched on and the chart plotter has been examined, it says ‘You switch on the board, and now the chart plotter has power.’

If the breaker board is switched on, but before the chart plotter is switched on and it has not been examined, it says ‘You switch on the board, you now have 12v power on the boat.’

And finally, if the breaker board is switched on and the player turns on the chart plotter, it says ‘You turn on the chart plotter and the screen comes to life.’

So far I have this code:

The chart plotter is a device in Cockpit. The chart plotter is scenery. The description is "The chart plotter is a 7 inch colour screen, used to display electronic charts. On the right is an on/off switch.". Understand "chartplotter" and "plotter" as chart plotter. The chart plotter can be switched on. One on/off button is part of the chart plotter. 

previous_attempt is a truth state that varies.

The Breaker Board is a device in the Engine Room. The Breaker Board is scenery. The description is "A breaker board with a switch marked 12v". The Breaker Board can be switched on. One on/off button is part of the Breaker Board. 

Before printing the name of the chart plotter while examining when the chart plotter is switched off and previous_attempt is false and the board is switched on:
	say "The chart plotter is off."

After switching on the chart plotter:
	if the Breaker Board is switched off:
		say "You try to switch on the chart plotter, but nothing happens.";
	otherwise if the Breaker Board is switched on:
		say "You turn on the chart plotter and the screen comes to life.";
		
Instead of switching on the chart plotter when the player tries switching on the Breaker Board:
	if previous_attempt is true:
		now the chart plotter is switched on;
		say "You switch on the board, and now the chart plotter has power.";
	otherwise:
		now previous_attempt is true;
		say "You switch on the board, you now have 12v power on the boat.";

The previous_attempt is introduced so that if they turn on the breaker and they haven’t examined the chart plotter, it just says “You now have power on the boat”. If they have checked the chart plotter before turning on the breaker, when the breaker turns on it tells you you have power to the chart plotter.

But Inform is tripping up and says:

You wrote 'Instead of switching on the chart plotter when the player tries switching on the Breaker Board'  , which seems to introduce a rule taking effect only 'when the player tries switching on the Breaker Board'. But this condition did not make sense, so I am unable to accept this rule.

I tried changing it to this:

Instead of switching on the chart plotter after the player switches on the Breaker Board:

And Inform tells me

'chart plotter' has the wrong kind of value: a device rather than an enumerated value.

I can’t work out if this is my logic or my syntax.

Do you want instead of switching on the breaker board?

2 Likes

Hi @Hidnook. That’s a great, thank you! One thing I hadn’t done was kill the power to the chart plotter if the breaker is turned off. This is what I’ve ended up with that appears to work after a cursory test:

check switching on the chart plotter:
	if the Breaker Board is switched off:
		say "You try to switch on the chart plotter, but nothing happens." instead;
	otherwise if the Breaker Board is switched on:
		say "You turn on the chart plotter and the screen comes to life.";
		
Instead of switching on the Breaker Board:
	if previous_attempt is true:
		now the chart plotter is switched on;
		now the Breaker Board is switched on;
		say "You switch on the board, and now the chart plotter has power.";
	otherwise:
		now previous_attempt is true;
		now the Breaker Board is switched on;
		say "You switch on the board, you now have 12v power on the boat.";
		
Check switching off the breaker board:
	if the Breaker Board is switched on:
		now the Breaker Board is switched off;
		now the Chart Plotter is switched off;
		say "You have turned off the 12v power supply.".

This now results in:

Engine Room
You are in the engine room short desc

>examine breaker
A breaker board with a switch marked 12v

The Breaker Board is currently switched on.

>turn off breaker
You have turned off the 12v power supply.

That's already off.

>examine breaker
A breaker board with a switch marked 12v

The Breaker Board is currently switched off.

>examine plotter
The chart plotter is a 7 inch colour screen, used to display electronic charts. On the right is an on/off switch.

The chart plotter is currently switched off.

The one thing I need to address now is this:

>turn off breaker
You have turned off the 12v power supply.

That's already off.

and this:

>turn on chart plotter
You turn on the chart plotter and the screen comes to life.

You switch the chart plotter on.

I guess the second line are defaults. How do I avoid that second line being returned? I think this is the ‘after’ rule but I’m not sure how to implement this.

You can use an instead of ... rule succeeds which will execute the snippet instead of following through with the action (instead), then do the action when you call rule succeeds. You had some redundant code that I removed, too.

code
instead of switching on the chart plotter:
	if the Breaker Board is switched off:
		say "You try to switch on the chart plotter, but nothing happens.";
	otherwise if the Breaker Board is switched on:
		say "You turn on the chart plotter and the screen comes to life.";
		rule succeeds;
		
instead of switching on the Breaker Board:
	if previous_attempt is true:
		now the chart plotter is switched on;
		say "You switch on the board, and now the chart plotter has power.";
	otherwise:
		now previous_attempt is true;
		say "You switch on the board, you now have 12v power on the boat.";
	rule succeeds;
		
instead of switching off the breaker board:
	now the Chart Plotter is switched off;
	say "You have turned off the 12v power supply.";
	rule succeeds;
1 Like

Thank you, I appreciate your help. I’m now rattling through this but one thing that is not working is capturing the previous_attempt rule. If I examine the chart plotter first, then turn the breaker on, it should tell me I have power to the chart plotter (it doesn’t turn it on, just provides power). However it is returning 'You switch on the board, you now have 12v power on the boat.".

previous_attempt is a truth state that varies.

The chart plotter is a device in Cockpit. The chart plotter is scenery. The description is "The chart plotter is a 7 inch colour screen.". Understand "chartplotter" and "plotter" as chart plotter. The chart plotter can be switched on. One on/off button is part of the chart plotter. 

The Breaker Board is a device in the Engine Room. The Breaker Board is scenery. The description is "A breaker board with a switch marked 12v". The Breaker Board can be switched on. One on/off button is part of the Breaker Board. 

Before printing the name of the chart plotter while examining when the chart plotter is switched off and previous_attempt is false and the board is switched on:
	now previous_attempt is true;
	say "The chart plotter is off."

Instead of switching on the chart plotter:
	if the Breaker Board is switched off:
		say "You try to switch on the chart plotter, but nothing happens." instead;
	otherwise if the Breaker Board is switched on:
		now the chart plotter is switched on;
		say "You turn on the chart plotter and the screen comes to life.";
		
Instead of switching on the Breaker Board:
	if previous_attempt is true:
		now the chart plotter is switched on;
		now the Breaker Board is switched on;
		say "You switch on the board, and now the chart plotter has power.";
	otherwise:
		now the Breaker Board is switched on;
		say "You switch on the board, you now have 12v power on the boat.";
		
Instead of switching off the breaker board:
	if the Breaker Board is switched on:
		now the Breaker Board is switched off;
		now the Chart Plotter is switched off;
		say "You have turned off the 12v power supply.".

It looks like this code only runs when the Breaker Board is already on. Delete that and it should work.

1 Like

Perfect. I think it is now all working correctly. I’m grateful of your help, @Hidnook. This has helped me understand conditional if statements too so this’ll give me a head start elsewhere in the game. Much appreciated!

Here is my final code:

previous_attempt is a truth state that varies.

The chart plotter is a device in Cockpit. The chart plotter is scenery. The description is "The chart plotter is a 7 inch colour screen, used to display electronic charts. On the right is an on/off switch.". Understand "chartplotter" and "plotter" as chart plotter. The chart plotter can be switched on. One on/off button is part of the chart plotter. 

The Breaker Board is a device in the Engine Room. The Breaker Board is scenery. The description is "A breaker board with a switch marked 12v". The Breaker Board can be switched on. One on/off button is part of the Breaker Board. 

Instead of switching on the chart plotter:
	if the Breaker Board is switched off:
		say "You try to switch on the chart plotter, but nothing happens." instead;
	otherwise if the Breaker Board is switched on:
		now the chart plotter is switched on;
		say "You turn on the chart plotter and the screen comes to life.";
		
Instead of switching on the Breaker Board:
	if previous_attempt is true:
		now the chart plotter is switched on;
		now the Breaker Board is switched on;
		say "You switch on the board, and now the chart plotter has power.";
	otherwise:
		now the Breaker Board is switched on;
		say "You switch on the board, you now have 12v power on the boat.";
		
Instead of switching off the breaker board:
	if the Breaker Board is switched on:
		now the Breaker Board is switched off;
		now the Chart Plotter is switched off;
		say "You have turned off the 12v power supply.".
		
Instead of examining the chart plotter:
	if the chart plotter is switched on:
		say "You examine the chart plotter, which is now on.";
	otherwise:
		now previous_attempt is true;
		say "The chart plotter is switched off innit.".

Happy to help! One last thing though: if you have an instead of rule, you can get rid of the instead within the snippet (which you haven’t done with the chart plotter code (sorry that was probably me replacing a check...instead with an instead of and forgetting to delete the redundant instead)).

Sorry, which instead of is redundant?

the instead doesn’t need to be there because it’s already within an instead of.

1 Like

Ah, yes, thank you.

side point, dunno for recreational boating in US, but in EU for every boat bigger than a skiff is mandatory keeping aboard the good ol’ manual/analog navigational tools & references.

Best regards from Italy,
dott. Piergiorgio.

Hi @Piergiorgio_d_errico I’ve been a liveaboard cruiser for the last 20 years. Don’t worry, the analogue stuff comes in later in the game!

1 Like