Acting on/comparing user-defined values

My goal is to have a value for how complete a room is, so I can

  1. have a mechanism to say “okay, if there are no loops that way, and all the rooms are done, and an option is set to block the player from going places they dont need, block them”
    1a) have something similar for last lousy points as well
  2. given a branch between two rooms that lead to separate areas, have a mechanism that directs the player to the part with more unsolved parts, if possible

The responses below went a good ways towards what I want, but it missed some cases. (I could of course use magic numbers to describe how complete a room is, but I’d rather use better programming practice if I can!)

They show how enumerations could be used e.g.

unstarted is always 0. done is always 100. started is always 25. nearly-done is always 75.

a room has a number called percent-done. percent-done is usually unstarted.

But I was trying to define a different value and act on that. Both my attempts below failed.

completions are a kind of value. the completions are unstarted, started, nearly-done and done.

a room has a completion called how-complete. how-complete of a room is usually unstarted.

a completion has a number called percent-done. percent-done of done is 100. percent-done of started is 25. percent-done of nearly-done is 75. percent-done of unstarted is 0. [first try, failed]

to decide which number is percent-done-1 of (c - a completion): [second try, failed]
	if c is done, 100;
	if c is nearly-done, 75;
	if c is started, 25;
	if c is unstarted, 0;
	50;

What is the right usage here?

If you want an enum to have properties, you need to use a table.

A completion is a kind of value. Some completions are defined by the Table of Completions.
Table of Completions
completion    percent-done
done    100
…

Then you can check “the percent-done of the how-complete of the location” and such.

For this one, you need to explicitly write decide on 100, unless you’re writing a “to decide whether” phrase (in which case the short forms “yes” and “no” are recognized).

No, you can give an enum properties. This works:

A completion is a kind of value. The completions are unstarted, started, nearly-done and done.
A completion has a number called percent-done.

The percent-done of done is 100.
The percent-done of nearly-done is 75.
The percent-done of started is 25.
The percent-done of unstarted is 0.

When play begins:
	repeat with C running through completions:
		say "[C]: [percent-done of C].";

I’m not sure why aschultz’s original try didn’t work.

2 Likes

Huh, I didn’t know that was a thing.

I’m also not sure why the original code didn’t work, then.

If the code from the original post is reproduced here verbatim from the project, then the (easily overlooked) culprit seems to be:

completions are a kind of value.

instead of the correct

A completion is a kind of value.
4 Likes

I was hoping it was something simple, but sometimes, when it’s something too simple, you feel silly just how simple it was!

Thanks for noting this–and I appreciate the discussion of other things to try. I have a tendency to say “oh, what I have is good enough” too often and this sort of not-quite-gratitude holds me back from sensible expansions that make ideas that work, work even better.

1 Like

No need to feel silly, it’s the sort of small slip-up that can happen very easily. :slight_smile:

“Bars are a kind of value” works for most situations, so it feels like a bug that this went wrong.