can't reuse daemon object in adv3lite

An astronaut on a deep space voyage goes about his daily business until it’s time to go to sleep. A daemon—bedtimeReminderDaemon—is created to fire very 3 turns to display a message that is contained in a shuffled event list. When the astronaut gets in his bed, the daemon is set to nil.

The astronaut goes about some more business until it is time for him to go to sleep again, when bedtimeReminderDaemon is once again activated (bedtimeReminderDaemon = new Daemon(…)) to recycle the same shuffled event list, also once every three turns (well, sort of, daemons always seem to start out at count 1 or 2, never 0, but that’s okay).

Except the second time through, the messages don’t display once every three turns, they display on turns 1 and 2 then skip 3, then 1 and 2 and skip 3.

I don’t understand what’s happening. It’s not the event list. I can reuse the shuffled list if I create a new daemon with a new name—bedtimeReminderDaemon, then anotherReminderDaemon— each time, but that makes management of daemon usage and destruction more complicated, since there are two separate object names to manage.

Is what I’m trying to do possible? How can I clear the daemon so that its name can be re-used? bedtimeReminderDaemon = nil doesn’t seem to do the trick.

Here’s a run-through in an isolated testbed environment…

Daemon is cleared in bed’s dobjFor(GetOut), created in dobjFor(Enter).

First time it’s created, I get the reminder messages on every third move…

The daemon is cleared then recreated, using the same name…

But now its every 1 and 2 skip 3, 1 and 2 skip 3…

Here’s the test bed code…

#charset "us-ascii"

#include <tads.h>
#include "advlite.h"

versionInfo: GameID
    IFID = '445C38A3-AD1B-4729-957A-F584600DE5C1'
    name = 'test'
    byline = 'by Jerry Ford'
    htmlByline = 'by <a href="mailto:jerry.o.ford@gmail.com">
                  Jerry Ford</a>'
    version = '1'
    authorEmail = 'Jerry Ford <jerry.o.ford@gmail.com>'
    desc = 'Testing daemon obj re-use.'
    htmlDesc = 'Testing daemon obj re-use.'

;

gameMain: GameMainDef
    initialPlayerChar = saturnExplorer
    paraBrksBtwnSubcontents = nil
   
;

saturnExplorer: Actor 'me;him' @bedroom
    ""
    firstName = 'John'
    lastName = 'Doe'
    person = 2
    pregnant = true
    probeIn = nil
;
bedroom: Room 'Bedroom' 'bedroom'
    "The bedroom is the room with the bed. <.p>"
    
    bedtimeReminderDaemon = nil
    
    bedtime()
    {
        bedtimeReminderText.doScript();
    }
;
+ bed: Container, Fixture 'bed'
    "The bed awaits. <.p>"
    
    isEnterable = true
    contType = In
    listOrder = 1
    
    dobjFor(Enter)
    {
        action()
        {
            "You get in bed. Reminder daemon is set to nil.<.p>";
            inherited;
            if(bedroom.bedtimeReminderDaemon != nil)
            {
                bedtimeReminderText.removeEvent();
                bedroom.bedtimeReminderDaemon = nil;
            }
       }
    }
    dobjFor(GetOutOf)
    {
        action()
        {
            "You get out of bed. New reminder daemon is created, with
            frequency of 3.
            <.p>";
            inherited;
            if(bedroom.bedtimeReminderDaemon == nil)
            {
                bedroom.bedtimeReminderDaemon = new Daemon (bedroom, &bedtime, 3);
            }
        }
    }
;

bedtimeReminderText: ShuffledEventList
{
    eventList = 
    [
        'Time for bed. <.p>',
        
        '<i>Yawn</i>.',
        
        'Tomorrow is another day. <.p>'
    ]
}
;

Any insights gratefully accepted :slight_smile:

Jerry

[rant](BTW—the new ad mechanism that has been implemented on this forum is a real PITA, with windows popping up repeatedly willy nilly, right in the middle of text entry in new message posts. I can live with ads, or at least I understand why web forums implement them, but the implementation here leaves a lot to be desired.)[/rant]

I’m looking at it in a hurry, but definitely you should call bedroom.bedtimeReminderDaemon.removeEvent(); instead of bedtimeReminderText.removeEvent();

Ah. Well. That does make a difference. Thanks. Seems to be working now.

Jerry

(BTW—my rant in the original post, about ads on this site, seems equally misplaced. Appears I picked up some malware that spiked my browser with bogus ads.)