Using ENABLE with QUEUE

Something I haven’t seen documented is the distinctions between the following:

<ENABLE <QUEUE I-FIGHT -1>>
<QUEUE I-SWORD -1>
<ENABLE <QUEUE I-THIEF -1>>

This is from the GO routine of Zork 1.

I know QUEUE is doing just what it sounds like, which is queuing whatever routine is listed to occur some number of times. I understand the -1 means every turn.

But why are two of those set with ENABLE and the one is not?

I’m guessing this means the obvious, which is that the middle routine (I-SWORD) is not enabled initially. But then why is it being set there? The “Learning ZIL” guide does not even show ENABLE, always showing QUEUE being used alone. The ZIL Guide (by Marc Blank) does use ENABLE and doesn’t show QUEUE being used alone.

Backing up my guess perhaps, there is a routine in Zork 1 that starts like this:

<ROUTINE SWORD-FCN ("AUX" G)
	 <COND (<AND <VERB? TAKE> <EQUAL? ,WINNER ,ADVENTURER>>
		<ENABLE <QUEUE I-SWORD -1>>

So it seems here the I-SWORD is now enabled every turn given the state of the game with respect to the sword.

Thus it seems the initial statement in the GO routine is just to make sure that I-SWORD can be enabled later.

But nothing in the documentation necessarily indicates this must be the case, unless I’m missing something.

1 Like

QUEUE adds a routine to the interrupt queue without enabling it, so it won’t count down or fire until it’s enabled.

In Zork I, I-SWORD is the routine that prints a message about the sword glowing when there’s danger nearby. It’s disabled by default, because you don’t start out carrying the sword. (The routine still checks whether you’re carrying the sword, so this doesn’t seem like much of an optimization… but I suppose it also meant the routine didn’t have to be paged in from disk.)

So why is it queued at all before you have the sword? To make the interrupts run in a specific order, I’m guessing: once the routine is queued, it stays in that position forever. I-THIEF moves the thief around, so the relative order of those two routines in the queue determines when you’ll see the sword start to glow as the thief gets closer.

4 Likes

In my game I am just using ‘queue’ to add interrupt routines to the queue. I don’t use ‘enable’ anywhere in my code - yet the routines still ‘fire’ when required. This suggests that the routine is ‘enabled’ by default - is that correct?

1 Like

ZILF’s library doesn’t actually implement ENABLE or DISABLE, so everything in the queue is enabled.

1 Like

QUEUE is usually called by ROUTINE, usually like this: <QUEUE I-SWORD -1>. Usually a number follows the first argument of QUEUE, ie 5 being after 5 turns an action is parsed (or 5 moves has passed), which at -1 is every turn after an action is parsed. This can be DEQUEUED or setting off the QUEUE () using just interrupt routine call and no further arguments. You can DEQUEUE any interrupt.