Checking current value of a variable during play

I tried searching, apologies if this is something easy or obvious. Or, worse still, a built-in debug command. I have a handful of numbers that vary that I’m tracking in my game. I’d like to be able to keep tabs on them during play. This is fine, so far as things go:

closet is a room.
B is a number that varies.
B is 77.
	
varcheckingB is an action applying to nothing.
understand "varcheckB" as varcheckingB.

Carry out varcheckingB:
let X be "The value of B is [B]";
say X.

However, it would be nice to either input the name of the variable for feedback or else get a list of some kind (probably too much data there). What do I need to do?

E: I think my main point of confusion is how to refer to the input and then convert it to a variable that Inform recognizes.

I was shocked to learn “showme” is not just a parser command but a debug command!

This worked for me. You can also keep track of more complex variables.

xxx is a truth state that varies.

every turn:
	showme the turn count;
	now xxx is whether or not xxx is false; [just to verify you can track more than numbers]
	showme xxx;
2 Likes

I never realized this could be done.

I’m looking for a way to have more flexibility when stating values. My example works, but only for a set value. What about getting some input?

If showme B as a player input worked, that would solve it, but it doesn’t. I’d like to be able to do something like

Value getting is an action applying to one [value? text? not sure].
Understand "get value for [?]" as value getting.
Carry out value getting:
say [here things fall apart for me]

I’m pretty sure that I could do this with a table, but that feels like another case of me overcooking things.

1 Like

as @aschultz says, “showme” will do what you want. You can also straight “say” variables. As far as the in-game logic for it, though, you’ll have to tie it to an action like the one you made. You won’t easily be able to create an action that can output the value of any named variable. “showme B” as a parser command doesn’t work because It’s not possible to refer to variables by name like that during play. Names like ‘B’ only make sense in your source code, because by the time execution happens, ‘B’ will be some actual number. Variables just point at values, and it’s those values that you interact with in your game. You can’t write something like understand "B" as B, because the parser doesn’t know about B. It only knows about whatever number B refers to, and it can’t tell you anything about that unless it’s given a way to check. An action like yours works because your “let…” line causes the program to check what B is so it can be printed.

1 Like
A numeric variable is a kind of thing.
A numeric variable has a number called the state.
Checking the state of is an action out of world applying to one visible thing.
Understand "check [any numeric variable]" as checking the state of.
Carry out checking the state of: say "The value of [noun] is [state of the noun]."

B is a numeric variable. The state of B is 4.
1 Like

I like Draconis’s approach for setting up a debugging action, but as I understood it the crux of your question is how to get that to work generically for any number that varies. The problem is that the name of the variable (from the source code) won’t be stored anywhere in a Glulx story file, so there’s no way to make use of it in a running story.

The provided approach creates game objects that can be parsed. I would suggest a slight modification: creation of a phrase to link the created proxy objects to the variables that you want to be able to display.

A numeric variable is a kind of thing. [no "state" property needed]

TC is a numeric variable. Understand "turn count" as TC. [an example built-in variable]

To decide which number is the state of (V - numeric variable):
    if V is:
	    -- TC: decide on turn count;
	    [new variable mappings here]
	    -- otherwise: decide on zero.

The exact functionality that you want is possible using the Z-Machine (that’s how the “infix” debugging module works in I6), but the requisite storage of global variable names in the story file just isn’t done under Glulx.

2 Likes

I’ll note that you can show a single variable as a one-liner:

Understand "varcheckB" as a mistake ("(DEBUG) B=[B].")

Writing one of these lines per variable you want to check isn’t much of a hardship.

4 Likes

Thanks everybody. All things being equal, I’ll go with brevity.

Hey cool, I was quite wrong about this being hard. I also didn’t know that about the Z-Machine. Thank you @Draconis, @otistdog, and @zarf

TIL that ‘understand “frob” as a mistake’ doesn’t advance the turn count. Cool. Another shortcoming of my initial example was the need for a rule to prevent checks from advancing the turn count.

Yep, mistakes are always “out of world”, and also override any other grammar lines. They’re one of the features I’m really glad to have in I7; in I6, adding a one-off response to an incorrect syntax (or an easter egg or whatever) required defining a whole new action, which wasn’t difficult but was certainly tedious.

2 Likes

If you hang your global variables from an object, you can use showme to get all their values.

conf-kind is a kind of object.
Conf is a conf-kind.
conf has a number called the num-var.
The num-var of conf is 8.

Section conf understanding (not for release)

Understand "conf" as conf.

This does mean persistently saying “blah of conf” to refer to them, of course.

1 Like