Torch problem

OurJud
29 Nov 2014, 00:56
Maybe it's just one of those nights, but I seem to be having issues with the simplest of tasks this evening.

I want to do the classic torch/need to find batteries thing, but I'm struggling.

I have a hut, inside of which is a torch (I've also put the batteries in here, too, but only for testing purposes).

I can take the torch, and I can take the batteries, but I can't figure out how to set the scripts and commands so that the torch only works when you have batteries.

The trouble is, if I want to allow players to use commands such as 'switch on torch' or 'turn on torch' - which I do, as that's the most likely command - I have to set the torch object to 'switchable'. I then have to set this to 'can be switched on'. But if I do that I get a sequence logic problem.

In the "Message to print when switching on (leave blank for default)" I put "The torch is dead".

Then I set a command pattern on the torch object, and add a script which checks for player carrying batteries; no batteries = torch dead.

I then set a command pattern on the batteries object, and add a script which runs a message describing you inserting the batteries when you input "use batteries with torch."

BUT, then when I type 'switch on torch' again, I get "The torch is dead" as this is the message I've set on the 'switchable tab'.

I can get around this by not having the torch set to 'switchable', but just 'Use/Give' instead. The only problem then is that it doesn't understand the command 'switch on torch', even though I have such commands added to the torch.

How am I meant to set this up so that the torch won't work until you've found and inserted the batteries?

Marzipan
29 Nov 2014, 04:02
Okay I think I got this.

1.) When the player picks up the flashlight, set a flag on it called 'nobattery'.

2.) Add your 'use battery on flashlight' verb or command or whatever you're going to use for that. When the player does it, unset the 'nobattery' flag.

3.) When switching the flashlight on, put a default message like 'You attempt to turn on the flashlight.'

4.) After switching it on, if the flashlight still has the flag 'nobattery', then print message 'The flashlight is dead.' And have the script switch it right back off.

5.) Then, 'else if the object does not have flag 'nobattery', go ahead and switch it on for real and print whatever message.

george
29 Nov 2014, 06:13
I would simplify things here. Try not to use a 'nobattery' flag because you know if the battery is in the torch (you can check with code if the player put the battery in). Put the 'torch is dead' message in a script that runs after switching on the object (checking if the battery is in there first of course). The logic problem here is that the 'torch is dead' message is in the wrong place.

Marzipan
29 Nov 2014, 15:42
I actually just figured out a simpler method too: make the flashlight a container you can put the batteries into, then use the 'if object contains...' script to check if they're in there when the player tries to switch it on.

OurJud
29 Nov 2014, 18:13
Nice work, people. Thank you.

I shall try these methods, starting with Marzipan's last idea, as it sounds the most straight forward.