Acting on a type and a number: potential code tuneup?

I have some code at the end-of-game menu that shows the player random puzzles they missed.

At the beginning, the game picks 1 of 5 obstacles from each pod and dumps them in the puzzle room. A command in the end menu will show the obstacles the player missed.

Now my current code works, but there is a lot of duplication in the “show seeds rule”.

a picaro is a kind of person. a picaro has a number called pod-ord. a picaro has a number called pod-num.
a pickup-line is a kind of thing. a pickup-line has a number called pod-ord. a pickup-line has a number called pod-num.

global-ord is a number that varies.

definition: a thing (called th) is current-list:
	if pod-num of th is global-pod-num, yes;
	no;

this is the show seeds rule:
	now global-pod-num is 1;
	say "Here is a complete list of randomizations with no spoilers. Ones you encountered this play-through are in [b]BOLD[r].";
	say "Here are the pods for Rodney's prosaic picaros:[line break]";
	while number of current-list picaros > 0:
		say "You will see one of pod [global-ord] at random: [list of current-list picaros].";
		increment global-pod-num;
	now global-pod-num is 1;
	say "Here are the pods for the parleys splayer players['] pickup lines:[line break]";
	while number of current-list pickup-lines > 0:
		say "You will see one pickup line from pod [global-pod-num] at random: [list of current-list pickup-lines].";
		increment global-pod-num;

This works, but the code feels bloated, and I feel like I’m missing some major concepts.

First, I was unable to get something like

to list-picaros:
    let current-num be 1;
    while number of picaros with pod-num of current-num > 0:
        say "One of [list of picaros with pod-num of current-num].";
        increment current-num;

to list-lines:
    let current-num be 1;
    while number of pickup-lines with pod-num of current-num > 0:
        say "One of [list of pickup-lines with pod-num of current-num].";
        increment current-num;

To compile. That is why I have the definition and the global-pod-num.

I was also hoping for pseudocode that could work on both the picaros and pickup lines.

to pod-list (ty - a type of thing):
    let current-num be 1:
    while number of (things of type ty) with pod-num of current-num > 0:
        say "One of [list of picaros with pod-num of current-num].";
        increment current-num;

this is the show-seeds rule:
    pod-list picaros;
    pod-list pickup-lines;

Thus I could just pod-list picaros; pod-list pickup-lines; and have some pretty nice code.

Is there a way to do better than what I did?

Do you have a more complete example? I can’t test without a few more things – say, two picaros and two pickup lines.

I suspect you’re just running up against Inform’s weird syntax. You absolutely should be able to break the code out into a “to” phrase (aka subroutine) and use a single one for both listings.

First, for reasons I don’t understand, Inform 7 says “kind” for what all other programming languages call a “type”.

Second, since this is a phrase which primarily prints stuff, you want it to be a “say” phrase, so it should start with something along the lines of

to say the endgame information about (K - a kind)

Inform 7 syntax for procedure (“to say”) and function (“to decide”) declarations confuses many people, because it’s so unlike declarations in most other languages, and I suspect this is what you’re hitting.

Also, Inform calls procedures/subroutines/functions “phrases” for reasons I also don’t understand. Inventing new terminology for well-established concepts was one of the poorest and worst design designs in Inform 7, IMO.

Anyway I hope that points you in the right direction.

1 Like

Your post is serendipitous, as I had code someone gave me that talked about “k - a kind” which I’d used and even changed without understanding what “a kind” was.

This is definitely pointing me in the right direction. I’ll add a full solution if I get it. While fully tuning this bit of code is low-priority for me compared to fixing bugs, I suspect if I do figure it out, it will be a huge confidence booster.

And I’d like to print a fuller example, but it gets detailed fast and might just confuse people more. I think you’ve discussed a lot of things I got confused about, and it certainly tripped a few things here and there I’d kind of said “oh, I guess I understand well enough,” and I “get” them a bit better now.

1 Like

The one that always gets to me personally is the function declaration. So I want a function, “foo”, which returns a value of type “int”, and takes no arguments. In inform 7, this is written as:

to decide which int is foo:

(followed by some code, which ends with the return statement decide on)

Now suppose I want a function, sqrt, which takes an int argument (number in Inform) and returns a float argument (real number in Inform). In inform 7 this is written as:

to decide which real number is the sqrt of (v - a number):

(followed by some code using the variable v, which again ends with the return statement decide on)

If you’re making a procedure do_something that doesn’t return a value, then you can potentially write

 to do_something:

But if it’s mostly printing text, it’s often advisable to make it a to say phrase.

Note…you may not be able to generalize both of the loops into one loop precisely because you may not be able to attach the necessary lists to the type; I don’t know if Inform will let you do that. You definitely should be able to break it out as two say-phrases, one for each loop, though

1 Like

I’m not sure I understand what you’re doing, but I wonder if a relation would work better than properties.

Lab is a room.

a picaro is a kind of person. 
a pickup-line is a kind of thing. 
Podnummery relates various numbers to various things.
The verb to podnum means the podnummery relation.

p1 is a picaro.
1 podnums p1.
p11 is a picaro.
1 podnums p11.
p2 is a picaro.
2 podnums p2.
p22 is a picaro.
2 podnums p22.

l1 is a pickup-line.
1 podnums l1.
l11 is a pickup-line.
1 podnums l11.
l2 is a pickup-line.
2 podnums l2.
l22 is a pickup-line.
2 podnums l22.

global-pod-num is initially 1.

Definition: a thing is current if global-pod-num podnums it.

To pod-list (name of kind of value of kind K):
  now global-pod-num is 1;
  while 1 > 0 begin;
    let F be the list of current K;
    if F is empty, break;
    say "One of [F].";
    increment global-pod-num;
  end while;

when play begins:
  pod-list picaroes;
  pod-list pickup-lines;
1 Like