A door that closes after X amount of turns upon opening

NEWBIE ALERT INFORM 7

I am trying to create additional variations of doors. I have the self explanatory code below. Please note: I have tried to write this code to work, but I have given up trying. I have written this out so it is self explanatory. I am aware this is VERY wrong but I just can’t seem to do it and now I need guidance. I would really appreciate it if you could help.


A door can be either magnetic or not magnetic. A door is usually not magnetic.
A door can be either swinging or not swinging. A door is usually not swinging.

If a door is swinging:
	now the door is closed in 3 turns;
	say "The [door in questions name] swings to a close." in 3 turns
	
If a door is magnetic:
	when the door closes it also becomes locked.
	
If a door is swinging and magnetic:
	then the door will close in 3 turns;
	say "The [door in questions name] swings to a close and becomes locked.".
	when it closes it becomes locked too.

Side note: I can make a door close and lock upon going through it, but I want to add in the factor of time as the door will close even if you don’t go through it

First off, this isn’t a general design discussion, this is an I7-specific question. I assume a moderator will move it at some point, but just bear this in mind for future questions.

Something like this should do the trick:

A door can be magnetic.  A door can be swinging.
A door has a number called swing time.

Carry out opening a door:
	now swing time of the noun is 3.

Every turn:
	repeat with item running through all open swinging doors:
		decrement swing time of item;
		if swing time of item is less than 0:
			now item is closed;
			if item is magnetic, now item is locked.

After closing a magnetic door:
	now the noun is locked;
	continue the action.

This doesn’t say anything when these things happen, but hopefully it should be obvious where to add that if you want it.

I think I realised i put it in the wrong place and posted it again in an i7 topic… I will have to get used to this. my bad! Sorry.

Would this work if I were to make it so that a door is swinging and magnetic?

Yes. Any door can have any combination of the two properties, including both.

Thank you so much i appreciate it.

It nearly worked, but it caused an error or two. Plus it didn’t allow for multiple logistics I was looking to get for a magnetic door to lock itself on it’s own even if it wasn’t opened after being unlocked. I also had to change “swinging” to “sprung” as I7 apparently didn’t like me giving a door that value.

this is what i did… there is code i don’t know how to do here… and im not sure if this will work. the code I don’t know how to do it the paragraph saying “When a door is unlocked…”

A door can be magnetic.
A door can be sprung.
A door has a number called spring time.
A door has a number called magnet time.

A door has a text called locking sound. Locking sound is usually "Click!"
A door has a text called closing sound. Closing sound is usually "Slam!"

Carry out opening an unlocked door:
	if the noun is sprung, now spring time of the noun is 3.

Every turn:
	repeat with item running through all open sprung doors:
		decrement spring time of item;
		if spring time of noun is less than 0:
			now noun is closed;
			say "[closing sound]! The [noun] closes itself.";

When a door is unlocked (either by player or by system)
	if the noun is magnetic, now magnet time of the noun is 3.

Every turn:
	repeat with item running through all magnetic doors:
		decrement magnet time of item;
		if magnet time of noun is less than 0:
			now noun is locked;
			say "[locking sound]! The [noun] locks itself.";

Thank you in advance.

ALSO… Is there someone to “hire” as it were to help write a novel through this system? I am keen to learn how to use it, but I am only new of course.

My apologies. Usually I test code out before posting it, but that time I didn’t.

It’s not really possible to do that sort of thing. What you can do is to define a common phrase (which can be helpful if there’s a lot of code involved or if you just want to keep magic numbers in one place):

To reset the magnet of (exit - a door):
	if exit is magnetic, now magnet time of exit is 3.

But you still have to find anywhere that unlocks the door and add reset the magnet of the noun (or another object as appropriate). If it’s a player command or an implicit action, you can do that in a carry out unlocking a door rule (similar to the opening one), but if you have other rules that can “manually” unlock doors (e.g. with now the basement door is unlocked, perhaps in some swipe card system) then you’ll have to add that there too.

You may have noticed that this is why I had two different places in the code that locked the door.

You’ll want to say all unlocked magnetic doors there, otherwise it will misbehave.

This needs to be more specific: [closing sound of the noun].

There’s a separate section dedicated to asking for collaboration.

This carry out command doesn’t seem to be liked by i7?

Carry out unlocking a door:
	if the noun is magnetic, now magnet time of the noun is 3.

It needs to be Carry out unlocking a door with, since the unlocking action requires specifying the key to be used. (You can see this in the Index, under Actions.)

Okay so I want this to be as autonomous as possible: I have made the below test map. It doesn’t fully work because it comes up with the error though. What am I doing wrong.

*** Run-time problem P31: Attempt to use a property of the 'nothing' non-object: property sprung time

I am guessing there is ALSO a smoother and more concise way to write the code I have made below.

[SPRUNG DOOR SYSTEM]

A door can be sprung.
A door has a number called sprung time. Sprung time is usually 0.
A door has a text called closing sound. Closing sound is usually "Slam"..

Every turn:
	repeat with doors running through all open sprung doors:
		if sprung time of the noun less than 1, now sprung time of the noun is 4.

Every turn:
	repeat with doors running through all sprung doors:
		if sprung time of noun is positive, decrement sprung time of noun.

Every turn:
	repeat with doors running through all open sprung doors:
		if sprung time of noun is 1:
			now the noun is closed;
			say "[closing sound of the noun]! The [noun] closes itself.".

[END SPRUNG DOOR SYSTEM]

[MAP]

The road is a room.
The player is in the road.
		
The big door is inside from the road.
The big door is outside from the house.
The big door is a door.
The big door is sprung.

[END MAP]

[LOGIC]

Every turn:
	say "Sprung Time: [sprung time of big door]".

[END LOGIC]

The problem is happening because you’re using noun in an Every turn rule, where it doesn’t exist – that only exists inside action rulebooks.

You need to replace noun with the name of your loop variable – in the case above, doors, but ideally you should probably pick a different name that isn’t going to get confused with something else.

There’s also not really any good reason to split up those things into three separate every turn rules (and a few good reasons not to). The way it was before was better. But I see why you’re trying that, how about this instead:

Every turn:
	repeat with exit running through all sprung doors:
		if exit is closed:
			now sprung time of exit is 0;
		otherwise:
			increment sprung time of exit;
			if sprung time of exit is greater than 3:
				now the exit is closed;
				now sprung time of exit is 0;
				if the player can see exit, say "[closing sound of the exit]!  [The exit] closes itself."
1 Like

DONE! This is a system such that you can now make doors “sprung” and “magnetic”. From what I hope we have created here, this code can be added to any code and give the ability to make any door auto close after X turns, or/and auto lock after X turns. I hope this is right! The magnetic door will also not automatically CLOSE upon locking. It will just lock upon being closed after the X amount of turns (just like any magnetic door). If you made a door magnetic AND sprung, it means it will lock and close automatically, just like a front door to a series of apartments for example. This also gives a change for you to “break the magnetic seal” and “now the door is not magnetic”… the same applies for “break the spring in the door” => “now the door is not sprung”. (you would have to implement the action of breaking yourself)

Thank you for helping me @mirality - this is hopefully a code that others can use too!
@mirality - Please let me know if there are any mistakes now in this code so I can edit it to make sure others can use it if they want to, otherwise its all good!! :slight_smile:

[SPRUNG DOOR SYSTEM]

A door can be sprung.
A door has a number called sprung time. Sprung time is usually 0.
A door has a number called sprung delay. Sprung delay is usually 3.
A door has a text called closing sound. Closing sound is usually "Slam".

Every turn:
	repeat with exit running through all sprung doors:
		if exit is closed:
			now sprung time of exit is 0;
		otherwise:
			increment sprung time of exit;
			if sprung time of exit is greater than sprung delay of exit:
				now the exit is closed;
				now sprung time of exit is 0;
				if the player can see exit, say "[closing sound of the exit]! [The exit] closes itself."
				
[END SPRUNG DOOR SYSTEM]

[MAGNETIC DOOR SYSTEM]

A door can be magnetic. A magnetic door is usually locked.
A door has a number called magnet time. Magnet time is usually 0.
A door has a number called magnet delay. Magnet delay is usually 1.
A door can be set-to-lock.
A door has a text called locking sound. Locking sound is usually "Click".

Every turn:
	repeat with exit running through all magnetic doors:
		if exit is locked:
			now magnet time of exit is 0;
		otherwise:
			increment magnet time of exit;
			if magnet time of exit is greater than magnet delay of exit:
				if exit is closed:
					now the exit is locked;
					now magnet time of exit is 0;
					if the player can see exit, say "[locking sound of the exit]! [The exit] locks itself.";

[END MAGNETIC DOOR SYSTEM]
2 Likes