# Every turn

Hi, I’m new to the forum.

I’m having a problem with creating viable starvation. I’m using the following code:

[code]Food is a kind of thing. Food is usually edible. Food has a time called the satisfaction period. The satisfaction period of a food is usually 360 minutes.

A person can be hungry or replete. The player is hungry.

Check eating something:
if the noun is not food, say “You can’t eat that!”
Carry out eating something:
now the player is replete;
hunger resumes in the satisfaction period of the noun from now.

At the time when hunger resumes:
starvation occurs in 30240 minutes from now;
now the player is hungry.
At the time when starvation occurs:
if the player is hungry, end the game saying “You have starved to death.”

Every turn when the player is hungry:
choose a random row in the Table of Hunger Complaints;
say “[hunger entry][paragraph break]”.[/code]

My problem is this snippet:

``Every turn when the player is hungry: ``

I want it to use my table of hunger complaints after a set number of turns for example every 50 turns, instead of every single turn.

I’ve tried every way to write it i can think of for the past 24 hours as well as googling, to no avail. Only success way making it appear 1 time after the set number of turns.

Can anyone help?

Thank you.

Wolf

P.S.

Forgot to add having trouble with ``` choose a random row in the Table of Hunger Complaints; ``` I can’t get to not be random but sequential.

This is a little cumbersome, and there is probably a more efficient way, but what about using a number variable as a counter, which increases every turn and resets to zero after it reaches 50. Then, you add an “if hunger pang counter is 50” condition to the rule which generates the text reminding the player about his empty belly.

Instead of using a table, why not use a formulation like

``Say "[one of] It's been a while since you ate last [or] Your stomach is starting to rumble [or] You're really quite famished [or] You feel like you're about to pass out from lack of nourishment [stoppping]".``

This will cycle through the entries sequentially until it reaches the last one, which then repreats (unless, of course, you have ended the game because the player has starved to death).

Robert Rothman

Alternately, if you really want to use a table, try reading the first entry when you want to print a hunger message, then “blank out the whole row”; I7 automatically skips over any blank lines when reading from a table.

If the game is designed with several food items, the player will be able to get hungry several times. In that case, blanking out the rows might be a bad idea, as the earlier messages in the table would no longer be used. If the messages are intended to show increasing levels of hunger, the table would need to be left intact so that the next period of hunger will start over with the early messages.

The problem Jim points out is equally present in the approach I had originally suggested. I suppose one way to get around it is to use a table, with a separate counter variable (which resets only when the player eats) to keep track of the overall degree of hunger. The “say” rule would then choose the message entry in the table which corresponds to the hunger entry which equals that counter variable.

Robert Rothman

Putting all that together, you should end up with something like this.

[spoiler][code]“Test”

Food is a kind of thing. Food is usually edible. Food has a time called the satisfaction period. The satisfaction period of a food is usually 2 minutes.

A person can be hungry or replete. The player is hungry.

Check eating something:
if the noun is not food, say “You can’t eat that!” instead.

Carry out eating something:
now the player is replete;
hunger resumes in the satisfaction period of the noun from now.

At the time when hunger resumes:
starvation occurs in 10 minutes from now;
now the turn offset is the remainder after dividing turn count by the set number of turns;
now line count is one;
now the player is hungry.

At the time when starvation occurs:
if the player is hungry, end the game saying “You have starved to death.”.

Line count is a number that varies. Line count is one.

The turn offset is a number that varies. The turn offset is zero.

The set number of turns is a number that varies. The set number of turns is two.

Table of Hunger Complaints
hunger
“It’s been a while since you ate last”
“Your stomach is starting to rumble”
“You’re really quite famished”
“You feel like you’re about to pass out from lack of nourishment”

Every turn when the remainder after dividing turn count by the set number of turns is the turn offset:
if the player is hungry begin;
choose row line count in the table of hunger complaints;
say “[hunger entry].[paragraph break]”;
if line count is less than the number of rows in the table of hunger complaints, increment line count;
end if.

The Testing Room is A Room. Some thought puzzles are food in the testing room.

Test me with “l / l / l / l / l / l / l / l / eat puzzles / l / l / l / l / l / l / l / l / l / l / l / l”.[/code][/spoiler]

This should pretty much do what you want. Also, the check eating rule should have an instead on the end.

Hope this helps.

The good news is that the code allows me to control the number of turns between each print out, but I’ve encountered two new problems as a result of the code.

[code]Food is a kind of thing. Food is usually edible. Food has a time called the satisfaction period. The satisfaction period of a food is usually 2 minutes.

A person can be hungry or replete. The player is hungry.

Check eating something:
if the noun is not food, say “You can’t eat that!” instead.

Carry out eating something:
now the player is replete;
hunger resumes in the satisfaction period of the noun from now.

At the time when hunger resumes:
starvation occurs in 10 minutes from now;
now the turn offset is the remainder after dividing turn count by the set number of turns;
now line count is one;
now the player is hungry.

At the time when starvation occurs:
if the player is hungry, end the game saying “You have starved to death.”.

Line count is a number that varies. Line count is one.

The turn offset is a number that varies. The turn offset is zero.

The set number of turns is a number that varies. The set number of turns is five.

Table of Hunger Complaints
hunger
“It’s been a while since you ate last”
“Your stomach is starting to rumble”
“You’re really quite famished”
“You feel like you’re about to pass out from lack of nourishment”

Every turn when the remainder after dividing turn count by the set number of turns is the turn offset:
if the player is hungry begin;
choose row line count in the table of hunger complaints;
say “[hunger entry].[paragraph break]”;
if line count is less than the number of rows in the table of hunger complaints, increment line count;
end if.[/code]

I’ve got the same code for thirst rules and it works fine so far, but the two codes now conflict.

[code]A thing is either drinkable or undrinkable

Drink is a kind of thing. Drink is usually drinkable. Drink has a time called the satisfaction period. The satisfaction period of a drink is usually 2 minutes.

Thirsty is an action applying to one thing.

A person can be thirsty or sated. The player is thirsty.

Check drinking something:
if the noun is not drink, say “You can’t drink that!” instead.

Carry out drinking something:
now the player is replete;
thirst resumes in the satisfaction period of the noun from now.

At the time when thirst resumes:
dehydration occurs in 10 minutes from now;
now the turn offset is the remainder after dividing turn count by the set number of turns;
now line count is one;
now the player is thirsty.

At the time when dehydration occurs:
if the player is thirsty, end the game saying “You have died from dehydration.”

Line count is a number that varies. Line count is one.

The turn offset is a number that varies. The turn offset is zero.

The set number of turns is a number that varies. The set number of turns is five.

Table of Thirst Complaints
thirst
“It’s been a while since you drank something”
“You’re very thirsty”

Every turn when the remainder after dividing turn count by the set number of turns is the turn offset:
if the player is thirsty begin;
choose row line count in the table of thirst complaints;
say “[thirst entry].[paragraph break]”;
if line count is less than the number of rows in the table of thirst complaints, increment line count;
end if.[/code]

This snippet of code is repeated in both:

``The set number of turns is a number that varies. The set number of turns is five.``

I can’t create separate turn lengths for each rule section. Only works if they are both the same.

Also for both of them the complaints tables are sequential but they but they don’t go abcd, hunger goes a,c,d skipping the second complaint. And thirst goes b,d skipping the first and third complaints.

You need to give your number variables distinct name, or Inform will conflate them:

```The hunger delay is a number that varies. Hunger delay is 5. The thirst delay is a number that varies. Thirst delay is 17.```

That’s because you have two separate rules that both increment the line count variable independently of each other.

After the first line in the hunger complaints table is said, the line count is set to 2. Therefore, when you move on the next every turn rule, the line count is already 2, and so the second line of the thirst complaints gets said (skipping the first thirst complaint), and after that the line count is set to 3.

A fix would be to blank out rows that has already been said and have the every turn rules always say the first of the rows that remain (as ChrisC mentioned), or to use a say phrase with variations (as Robert Rothman suggested).

Thank you for the delay code, that did the trick. I’m afraid I don’t understand the blank row and say stuff (in terms of how to implement.)

I tried
“”
blanks on the table but it just made a mess of things.

This is my first IF project.

Saying the text with variations is a piece of cake actually:

```Every turn when the remainder after dividing turn count by the hunger delay is the turn offset: if the player is hungry begin; say "[one of]It's been a while since you ate last [or]Your stomach is starting to rumble [or]You're really quite famished [or]You feel like you're about to pass out from lack of nourishment [stopping]."; end if.```

Thank you so much Felix, and everyone before.

I’ve got one final problem with hunger and thirst remaining now that all the bugs have gone. When I eat something, the hunger goes away and then when it returns and reaches the final message I die, perfect. But with drinking, I drink a bottle of water, the thirst messages do not disappear and I can’t seem to die from dehydration.

[code]A thing is either drinkable or undrinkable

Drink is a kind of thing. Drink is usually drinkable. Drink has a time called the satisfaction period. The satisfaction period of a drink is usually 2 minutes.

Thirsty is an action applying to one thing.

A person can be thirsty or sated. The player is thirsty.

Check drinking something:
if the noun is not drink, say “You can’t drink that!” instead.

Carry out drinking something:
now the player is replete;
thirst resumes in the satisfaction period of the noun from now.

At the time when thirst resumes:
dehydration occurs in 10 minutes from now;
now the turn offset is the remainder after dividing turn count by the thirst delay;
now line count is one;
now the player is thirsty.

At the time when dehydration occurs:
if the player is thirsty, end the game saying “You have died from dehydration.”

Line count is a number that varies. Line count is one.

The turn offset is a number that varies. The turn offset is zero.

The thirst delay is a number that varies. Thirst delay is 1.

Every turn when the remainder after dividing turn count by the thirst delay is the turn offset:
if the player is thirsty begin;
say “[one of]It’s been a while since you drank some fluids
[or]You’re really quite thirsty
[or]You feel like you’re about to pass out from dehydration
[stopping].”;
end if.[/code]

My item in the test was ``` There is an apple and a bottle in A Refrigeration Unit. The bottle contains water. ```

In my food and drink rules section I made sure to add: ``` Water is drink. ```

P.S. I do have code for the bottle so that’s not the issue.

Drinking mistakenly makes you replete (like eating), not sated.

I also don’t think you want “Thirsty is an action applying to one thing” in there – I don’t think it’s doing anything, but you don’t need it.