counted turns and dropping things

After the player has performed a specific action, I want the player to have bad luck. The idea is that once the action is performed, then every five turns or so the player drops a random item and it goes back to its original position. I haven’t the slightest idea how to achieve this…

More specifically, here’s an example of a sorce text that I know won’t work but that hopefully exemplifies what I’m trying to accomplish.

Hyar is a room. A chest is an open unopenable container in Hyar.   

A coin is in Hyar.  A skull is in Hyar.  A sword is in Hyar.  A pistol is in Hyar.  A torch is in Hyar.

Every five turns:
      if the skull is in the chest:
         now the player is not carrying a random carried thing.

Any ideas on how I can effectively achieve this?

[code]A thing has an object called the original holder.
When play begins:
repeat with the item running through things:
now the original holder of the item is the holder of the item.
To reset the position of (the item - a thing): move the item to the original holder of the item.

At the time when the curse is triggered:
reset the position of a random thing enclosed by the player;
the curse is triggered in five turns from now.
[/code]

Start the bad luck with “the curse is triggered in 5 turns from now” and it’ll repeat thereafter.

EDIT: Though I might have misunderstood you! Let me know if this isn’t what you want. You could also dump the timed events, and check if the turn count is divisible by 5 in your “every turn”. My code gives the player no way to end the curse, the “every turn” would let the player escape the bad luck by removing the skull or what have you.

Here’s another way to do it using a recurring scene:

Hyar is a room. A chest is an open unopenable fixed in place container in Hyar.   

A coin is in Hyar.  A skull is in Hyar.  A sword is in Hyar.  A pistol is in Hyar.  A torch is in Hyar.

A thing can be curse-droppable. A thing is usually curse-droppable.
The coin is not curse-droppable.

A thing has an object called the original holder.

When play begins:
	repeat with the item running through things:
		now the original holder of the item is the holder of the item.

To reset the position of (the item - a thing):
	move the item to the original holder of the item.

Skull Curse is a recurring scene.
Skull Curse begins when the skull is in the chest.
Skull Curse ends when the skull is not in the chest.
Skull Curse has a number called turns.

When Skull Curse begins: 
	now the turns of Skull Curse is 0.

Every turn during Skull Curse:
	increment the turns of Skull Curse;
	if the remainder after dividing the turns of Skull Curse by 5 is 0:
		let the chosen thing be a random curse-droppable carried thing;
		if the chosen thing is not nothing:
			say "The skull's eyes flash, and [the chosen thing] vanishes.";
			reset the position of the chosen thing;
		otherwise:
			say "The skull's eyes flash with a hint of annoyance.";
	otherwise:
		say "The skull glares at you from within the chest.";
		
Test me with "take all / put skull in chest / z / z / z / z / i / l / z / z / z / i / l / z / take skull / z / z / z / z / z / put skull in chest / z / z / z / z / i / l / z / z / z / i / l / take pistol / z / z / i / l"

If the skull can be inside something else, you might want the scene begin/end conditions to test for “enclosed by the chest” rather than “in the chest”, depending on how you want things to work.

Also, any items that begin the game in the player’s inventory should probably be made not curse-droppable so that they don’t “vanish” from the player’s inventory and return to their original position… in the player’s inventory.

thanks guys! i think it worked! I decided to go with using scenes, since I have had yet to use scenes up until now and thought this would be a good learning experience for me. i need to conduct some more thorough testing, but it’s proving effective so far. A couple of things I am confused about though:

  1. I have never seen something like: “(the item - a thing)” before. Is putting it in parentheses like this a way of re-naming a thing as an item?

  2. is “holder” a built-in characteristic of Inform? I’ve never seen that before, either.

EDIT: So I seem to have encountered a difficulty. I wanted to have the scene end under different conditions (other than removing the object from the container), such as putting a different object into the container, but I got the message “The scene change machinery is stuck.” What do you think I might have done wrong to cause the error?

If going off vlaviano’s above example, I made the following changes:

Blood is a thing.

[I used this following line instead of "Skull Curse ends when the skull is not in the chest."]
Skull Curse ends when the blood is in the chest. 

Everything else remained the same.

“Holder” is whatever directly encloses the object: a container, supporter, person, or room. If I’m holding a box, in which is a keyring, on which is a key, the holder of the key is the keyring. (Whereas the location of the key is my location.)

Those parentheses define an argument to a function, so to speak. You use them when defining a “To:” phrase.

This kind of error happens with recurring scenes when the scene begin condition and the scene end condition are both true at the same time. To solve it, change the conditions to ensure that they are mutually exclusive.

If you have:

Skull Curse begins when the skull is in the chest.
Skull Curse ends when the blood is in the chest.

then, if both the skull and the blood are in the chest at the same time, both conditions will be true, and you’ll have a problem.

To fix it, I’d do something like:

Skull Curse begins when the skull is in the chest and the blood is not in the chest.
Skull Curse ends when the skull is not in the chest or the blood is in the chest.

it worked, thanks!