A simple flashlight problem.

Hello there. I was just wondering if anyone could help me on this. Here’s the thing:

I’m working in i7 and I am trying to have a flashlight that is a fully takeable, dropable, etc. kind of object. I’ve been trying to make it so it is possible to turn on/off the flashlight, and when turned on it lights up a darkened room (my later thoughts include only lighting up surfaces that you ‘look’ at, but that is a different question altogether and I’m not going to focus on it). It also runs down after having it on for a set amount of time and can be turned back on using, albeit non-logical, self recharging batteries. Here is my code.

[code]The flashlight is an object. The flashlight can be switched on. The flashlight is switched on. The flashlight is inside the pantry.

Carry out the flashlight switching on:
Now the flashlight is lit;
The flashlight is switched off in 20 turns from now.

At the time when the flashlight is switched off:
say “The flashlight flickered away it’s last drop of light, not turning back on until the batteries charged up.”;
Now the flashlight is switched off;
The flashlight is switched on in 10 turns from now.

At the time when the flashlight is switched on:
say “The torch brings itself back to life and fills the room with calming light.”;
Now the flashlight is switched on.[/code]

My apologies if this is written out sloppily or unorganized (that might actually have something to do with the problem). Anyways, for the life of me I cannot get this to work. Any advice? Thanks.

It would probably be easiest to use the built-in device kind, and just give the flashlight an explicit battery charge and decrement it every turn while it’s lit:

The flashlight is a device. The player carries the flashlight.

The flashlight has a number called the charge. The charge of the flashlight is 20.
Definition: the flashlight is charged if the charge of it is greater than zero.

Carry out switching on the flashlight: if the flashlight is charged, now the flashlight is lit.
Carry out switching off the flashlight: now the flashlight is unlit.

Every turn while the flashlight is lit:
	decrement the charge of the flashlight;
	if the flashlight is not charged, now the flashlight is unlit.

Edit: Oh, wait, I forgot the magic recharging function. You could implement it something like this:

Every turn while the flashlight is switched off [or plugged into a charger or something] and the charge of the flashlight is less than 20:
	increase the charge of the flashlight by two.

Note that this won’t automatically switch the light back on when it’s fully charged, although you certainly could make that happen if you wanted.

Thank you for the help. Much appreciated.