Help with a Variable

Hi, I am having some trouble finding information on how to set something up.

Basically in my game the player character has a vivarium containing a snake which they can open at the start of the game. I would like for the snake to pop up somewhere later in the story if the character leaves the vivarium open without closing it at the start of the game. I imagine I am overlooking somthing quite simple on how to do this but it is quite specific so I am hoping someone here can help?

Thanks for any help in advance. I am very new to this software and have never really done coding before so I may just be asking a dumb question but I hope someone can help.

Hello! You won’t actually need to set up a separate variable for this; you can test whether or not something is open with code like this:

	if vivarium is open:
		say "Oops, you left that vivarium open!";

That might be all you’re looking for, but if it doesn’t answer your question let me know and I can include a little more detail on how this code might be used.

There are various ways to do this, one might be with Scenes (see chapter 10 in the docs):

The Living Room is a room.

The vivarium is a transparent closed openable container in the Living Room.

The snake is an animal in the vivarium.

Snake-Escape is a scene.
Snake-Escape begins when the vivarium is open for the sixth turn.

When Snake-Escape begins:
	now the snake is in the Living Room;
	say "You get a nagging feeling that you should check on your vivarium.".

Thank you, I have done this in other places but this one I wanted to be somthing for the player to be able to forget to do which can lead to hijinks.

Also thanks StJohnLimbo that seems perfect Thanks for pointing out where it is in the documentation as well. The documentation is nice and useful but it helps when you know which section to look in.

A scene is a good way of doing this! But just to point it out, that message about forgetting to close the vivarium is a placeholder; you don’t have to warn the player like that. Instead, you could put lines of code there that silently move the snake around, or do just about anything you want.

Oh I didnt know about that. That may be the way to go then. At this point I am playing around with the software. But this escaped pet sequence would be quite fun in the final game I think. I shall give both a try.

Or even simpler:

The Living Room is a room.

The vivarium is a transparent closed openable container in the Living Room.

The snake is an animal in the vivarium.

Every turn when the vivarium has been open for exactly 6 turns:
	now the snake is in the Living Room;
	say "You get a nagging feeling that you should check on your vivarium.".

Yeah, agreed, doing this as a scene feels a little overcomplex. Though in the admittedly edge case where the player re-closes and then re-opens the empty vivarium, the “niggle” text will fire once more, so adding an “if the snake is in the vivarium” conditional might be prudent.

1 Like

However, if you want your snake to do interesting stuff after it has escaped, the scene approach is better because you can then write

The Living Room is a room.

The vivarium is a transparent closed openable container in the Living Room.

The snake is an animal in the vivarium.

Snake-Escape is a recurring scene.
Snake-Escape begins when the snake has been in the vivarium for at least 6 turns and the vivarium has been open for at least 6 turns.
Snake-Escape ends when the snake is in the vivarium.

When Snake-Escape begins:
	now the snake is in the Living Room.
	
every turn during Snake-Escape:
	say "The snake is on the loose!"
	[or your code for the snake to do interesting things when on the loose instead]
1 Like