Simple Graphical Window by Emily Short

I have been experimenting with the Simple Graphical Window extension in a small test project. Because the extension automatically creates a single graphics g-window at startup, I used this command to close that window since I wasn’t using it.

When play begins:
    Close the graphics window;

After some additional experimentation I transferred my graphics window code over to an existing game with a much larger code base. When I run that code I issue the same command to close the graphics window in the When Play Begins block.

But a graphics window still appears above the main window. This is strange since the command to close the graphics g-window is called in the When Play Begin block (I added “say” statements to each of the window creation commands in that block to see when they are being called).

I find this strange and assume there must be something in this larger 40,000+ word code base that is causing this graphics window to be drawn even though I have closed it (when I try and draw an image into this unwanted graphics window I get a Glk Error - “glk_image_draw_scaled called with an invalid winid”).

While I debug the code to find the root cause I thought I would post here in case anyone else has ever encountered an issue like this or has some debugging suggestions.

Two questions:

  1. Has anyone every encountered an issue like this?

  2. Aside from reviewing code, putting in “say” statements, is there a better way to debug this in the Inform IDE (I am using 6M62 v1.68.1)?

1 Like

Okay, I figured it out and the solution was simpler than I thought.

In my 40,000+ word game I had the When Play Begins code before the section where I included the extensions.

Volume - Beginning The Story

When play begins:
    close the graphics window;
    open the right-sidebar window;
    ...

Volume - Setup

Part - Extensions

Include Flexible Windows by Jon Ingold.
Include Simple Graphical Window by Emily Short.

I had been reading the documentation about how extensions are compiled into the story source code and that made me look at my prototype example. In that example, the two Volume sections were switched, with the Extensions section coming before the Beginning The Story section.

Volume - Setup

Part - Extensions

Include Flexible Windows by Jon Ingold.
Include Simple Graphical Window by Emily Short.

Volume - Beginning The Story

When play begins:
    close the graphics window;
    ...

On a hunch I cut and pasted the Beginning The Story section in the 40,000+ word game so it appeared after the Extensions section. When I compiled the code the spurious graphics window does not appear.

I assume it has something to do with the way extension code is compiled into the main code. I don’t understand 100% why my solution works so if anyone has a more “formal” explanation please let me know (errors like this have happened to me before and the fix, while simple, is frustrating to figure out sometimes).

Note: I also figured out that I could have made my own personal copy of the Simple Graphical Window extension, modifying it so it didn’t create a graphics window, but I didn’t want to do that for a variety of reasons (see §27.3. Built-in, installed and project-specific extensions in the Inform documentation for details).

My guess is that the window is getting opened in a When Play Begins rule in the extension, and since neither of those rules is more specific than the other, they get run in source code order. Which means you were closing the window before it opened!

If you don’t want this code to depend on the order of inclusion, put your window-closing code in a last when play begins rule, which ensures it’ll be run after all the rest.

1 Like