How to increase a variable by 1 every time I do a certain action

I want to make a variable increase every time i wait but am not sure how to do it.

Someone help me

1 Like

You could do it like this:

procrastination counter is a number that varies.

Before waiting:
	increment the procrastination counter;
	say "You have waited [procrastination counter] time[s].".
7 Likes

Thankyou so much!

I will share the project here once it is done if you want to see it.

1 Like

My code before adding the new section is the following:

’ ’ ’

[Rooms]

The Cellar is a room. The description of the Cellar is “[first time]You wake up in a cold cellar with a large compass shape on the floor. Your guess that the compass is accurate and make all of your movements based of of it. You don’t remember much from before you were put here but one thing you are certain of is that you are hungry. You can only see a few things in the Cellar. You can see a large metal door to the north and a metal key in the corner of the room. There is also a yellow handled screwdriver.[only]”

The second cellar is a room. The description of the second cellar is “[first time]Once you get into the room you hear your stomach rumble. You can see a small flap in the wall that only a food tray could come out of. Maybe if you wait some food might come out.[only]”

Raddish is a room

Pizza is a room.

The tunnel is a room. The description of the tunnel is “[first time]You don’t see anything here. You had better keep moving.[only]”

[Positioning]

There is a flathead screwdriver in the Cellar.

The Metal door is north of Cellar

The Second Cellar is north of the Metal Door

The Metal Key is in the Cellar

In the second cellar is a Food Flap

The tunnel is east of the air vent entrance.

The air vent entrance is east of the second cellar.

[doors]

The Metal Door is a door. The Metal Door is lockable and locked. The matching Key is the Metal Key.

The air vent entrance is a door. the air vent entrance is lockable and locked.

[Variables]

Plop is a number variable

Lol is a number variable

Screw is a number variable

[Fixed in place]

The air vent entrance is fixed in place

[understand]

Using is an action applying to one thing. Understand “Use [something]” as Using.

[Instead]

Instead of using screwdriver:
If player is in second cellar:
If screw is 4:
say “there are no more screws to unscrew”;
Otherwise:
If screw is 3:
say “you unscrew one of the screws to the air vent which causes the cover to fall to the floor with a clang.”;
now screw is 4;
now air vent entrance is unlocked;
Otherwise:
If screw is 2:
say “You unscrew one of the screws to the air vent.”;
now screw is 3;
Otherwise:
If screw is 1:
say “You unscrew one of the screws to the air vent.”;
now screw is 2;
Otherwise:
If screw is 0:
say “you unscrew one of the screws to the air vent.”;
now screw is 1;
Otherwise:
say “You don’t see anything to unscrew in this room. Maybe check the room next door.”

Instead of taking metal key:
say “You pick up the metal key and feel the coolness on your hand. It must have been on the floor for a while.”;
now the player has the metal key;

Instead of taking flathead screwdriver:
say “As you pick up the yellow handled screwdriver you inspect it closly. You see that it has a flat end that will only work on specific screws.”;
now the player has the flathead screwdriver

Instead of unlocking metal door with metal key:
say “You slide the key into the keyhole perfectly and twist it. You hear the expectedly loud CLICK of the door. Once you unlock the door you try to pull the key out of the keyhole but it gets stuck.”;
now the metal key is nowhere;
now the metal door is unlocked;

[Before]

before going north:
If player is in the Cellar:
If the Metal door is locked:
say “The metal door seems to be locked”;
stop;
Otherwise:
now the player is in the Second Cellar;
say “You walked past the Metal door and into the Second Cellar[line break]”;
stop;

before going south:
If player is in second cellar:
If the Metal door is locked:
say “The metal door seems to be locked”;
stop;
Otherwise:
now the player is in the Cellar;
say “You walked past the Metal door and into the Cellar[line break]”;
stop;

’ ’ ’

Not code

It is quite long XD

Another thing that I want to do is to make it so every time I wait another food tray (item) is put into the room. How would I be able to do that? I know that it has something to do with make a randomly targeted item and then saying now the target something is in the [room]. Would you be able to Help me with something like that?

Thankyou in advance : )

Why did you post the source code above?

There are many different ways to do this. Which one is most suitable depends on what you want to achieve. Identical objects will be quite complicated to realize in Inform 7 and it is probably easier to solve it differently. A very simple solution could, for example, be a variant of my example above:

Canteen is a room.

Food tray counter is a number that varies. Food tray counter is 23.

A line of food trays is in the canteen. The description is "A quick count reveals that there are [food tray counter in words] food trays in the line.".

Instead of waiting in the canteen:
	increment the food tray counter;
	say "While you wait indecisively, another food tray is pushed out of the opening in the wall and joins the others of its kind.".

Sorry about that… I tried to delete the code but it keeps on undeleting for some reason. I don’t know why it just undeletes. I have tried to delete it so many times.

I am not quite sure if you understood what I said because I said it in a bad way or for some other reason. You have been super still, but what I want is that every time I wait another actual item moves into the room.

for example (I know this doesn’t work)

before waiting:
now another food tray is in the cafeteria;

I want the food tray to be an actual item that you could pick up or drop or use as something else.

sorry if I wasn’t clear the fist time.

(also, How do I put the code in that box thing?)

Thanks in advance : )

Before figuring out the code for this, are you sure that you want this function in your game? If you have a specific use for the food tray, you only need one. Having more will lead to disambiguation issues, like:

TAKE FOOD TRAY
Did you mean the food tray, the food tray, the food tray, or the food tray?

Other than the one game-relevant one, you can just have the counter if you need to as shown above.

For a single line, use `code`, producing code. You can also use the </> button in the toolbar. For multiple lines, surround the block in ```, or highlight the block and select the </> button. Note how you have to scroll in order to read all of the code, preserving line breaks.

xyzzying is an action out of world.
Understand "xyzzy" as xyzzying.

Check xyzzying: say "You realize that you're just playing a text adventure and that none of this is relevant at all."
2 Likes

What Hidnook says is absolutely right.

There is a good example in the Manual that comes with your Inform7 IDE:
Extra Supplies

If you combine it with the code above you’ll get something like this which hopefully does the trick:

Canteen is a room.

Food tray counter is a number that varies. Food tray counter is 23.

A line of food trays is in the canteen. The description is "A quick count reveals that there are [food tray counter in words] food trays in the line.".

Instead of waiting in the canteen:
	increment the food tray counter;
	say "While you wait indecisively, another food tray is pushed out of the opening in the wall and joins the others of its kind.".
	
Understand "tray" as the line of food trays when the food tray is not visible.

There is a food tray. The description is "A food tray made of the usual and at the same time unfathomable material. Is it made of plastic or chipboard? You'll probably never find out.".

Instead of taking the line of food trays: 
	if the food tray is off-stage: 
		move the food tray to the player;
		decrement the food tray counter;
		say "You take a food tray, probably more out of habit than reason."; 
	otherwise: 
		say "You've already taken one and certainly don't need a second.".
1 Like

Thanks To both of you for being helpful.

I should have thought of what you said and you were a huge help with my project : )

(me testing that the code thing works)

does this work?
1 Like

I have another problem that is here

Thanks for your help again :grinning:

EDIT:

It is solved now.