Dial and skipping missed numbers

Hello. I’m a bit stumped in a logic problem that seems simple. Let’s say that we have a dial that goes from one to 100. The aim is to first turn the dial to 20, then 40, then 48, then 65, then 90, but the player can turn the dial as far as possible starting from one (you can’t turn it backwards). Let’s say that the player turns it to 70 right off the bat, then from 70 to 100. I would need a way to count how many of these “mandatory stops” the player has skipped (if if the player turns the dial to 20, then 40, then to 100, I would need to know they skipped three steps).

This feels like it should be easy but ugh :slight_smile:

Would something as simple as :

Table of Stops
At has_stopped
20 0
40 0
60 0

then set has_stopped to 1 when player stops there.

Then to count how many missed stops, just iterate through table counting how many has_stopped is set to one.
Or if you wanted to say how many stop player has missed between 20 and, say 80, it’s just the number of rows until the value in the At column is greater than where the player has stopped.

This would be quite extensible.

Or you could use a list of numbers {20, 40, 48, 65, 90} - then if a player dials a number, you remove it from the list. When 90 (or higher) is reached, you look at the number of entries in the list (actually it’s called “number of members” if I remember correctly) and you know how many steps the player skipped. (Too lazy to write some code right know, do you know how to do it?)

Thanks, that helped! Especially the latter sounds exactly what I’m looking for. Haven’t used lists too much in Inform 7 yet but looks straightforward enough.

Ugh okay, now I remember the trouble I’ve had with lists - I don’t quite get the scope of variables.

Let’s say that I have a “tune to” command, and I have a list of “tunestops”. Where should I do the “let tunestops be {20, 40, 48, 65, 90}”? I did that in “when play begins” and in the carry out of “tune to” I have " remove number understood from tunestops, if present."

What I get is “Problem. You wrote ‘remove number understood from tunestops, if present’ , but ‘number understood’ has the wrong kind of value: a number rather than a list of values.”

What am I missing here?

Could you post your code?

My code is, for the salient points, like this. So, what I’m trying to do is that there is a scene in the game where the player has to tune through a sequence of numbers from say 1 to 100, and when we reach y, the scene stops and I’d need to know how many stops they missed.

[code]When play begins:
let tunestops be {20, 40, 48, 65, 90}.

tunedto is a number that varies. tunedto is 1.

tuning to is an action applying to one number.

Understand “tune to [number]" as tuning to.

Check tuning to:
if the tunedto is 100:
say “debug: max at 100?” instead;
else if the number understood < tunedto:
say “debug: going lower”;
stop.

Carry out tuning to:
now tunedto is the number understood;
remove number understood from tunestops, if present.
[/code]

Maybe try making tunestops a global variable or an action variable for the tuning to action? I think if you create the list as a temporary variable with a “let” in when play begins then it won’t work well when you try to refer to it in a different rule. If you want to make it global you can say “Tunestops is a list of numbers that varies” and then when you want to initialize it “Now tunestops is…” though in this case I think you could actually just skip the “When play begins” rule and write “Tunestops is {20, 40, 48, 65, 90}” by itself as an initial assertion.

So this code works (once you add a location):

[code]Tunestops is a list of numbers that varies. Tunestops is {5, 15, 30, 45, 60}.

Tuning to is an action applying to one number. Understand “tune to [number]” as tuning to.

Carry out tuning to: remove the number understood from tunestops, if present.

Report tuning to: say “You tune to [number understood]. Remaining tunestops: [tunestops].”[/code]

Obviously you need to use your tunedto somehow to prevent the player from tuning down, etc.

All right, cheers - one of the things I’ve just never got the grip of in Inform 7 is the variable scope and the keywords related to that.

Basically as I understand it “let” creates a temporary variable. “…is a whatever that varies” creates a global variable.