Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Neverwinter Nights: Enhanced Edition has been released! Visit nwn.beamdog.com to make an order. NWN:EE FAQ is available.
Soundtracks for BG:EE, SoD, BG2:EE, IWD:EE, PST:EE are now available in the Beamdog store.
Attention, new and old users! Please read the new rules of conduct for the forums, and we hope you enjoy your stay!

Problems with SetTime function?

Has anybody had problems with SetTime?

In a module OnLoad event, we set the date/time based on some function based on the real world time. Setting the date with SetDate() is spot on, but the SetTime function appears flaky. Sometimes it will set the time correctly, sometimes it's 2-3 hours ahead of what's requested.

For example:

This:

    debug("Internal date is " + IntToString(GetCalendarYear()) + "/" + iht_pad(GetCalendarMonth()) + "/" + iht_pad(GetCalendarDay()) + " " + iht_pad(GetTimeHour()) + ":" + iht_pad(GetTimeMinute()));

    struct date d = GetIGDate();
    debug("Date Args:  " + IntToString(d.year) + ", " + IntToString(d.month) + ", " + IntToString(d.day));
    SetCalendar(d.year, d.month, d.day);
    debug("Internal date is " + IntToString(GetCalendarYear()) + "/" + iht_pad(GetCalendarMonth()) + "/" + iht_pad(GetCalendarDay()) + " " + iht_pad(GetTimeHour()) + ":" + iht_pad(GetTimeMinute()));

    debug("Time Args:  " + IntToString(d.hour) + ", " + IntToString(d.min) + ", 0, 0");

    SetTime(d.hour, d.min, 0, 0);
    debug("Internal date is " + IntToString(GetCalendarYear()) + "/" + iht_pad(GetCalendarMonth()) + "/" + iht_pad(GetCalendarDay()) + " " + iht_pad(GetTimeHour()) + ":" + iht_pad(GetTimeMinute()));
    WriteTimestampedLogEntry("=================");
    SetTime(d.hour, d.min+1, 1, 1);
    debug("Internal date is " + IntToString(GetCalendarYear()) + "/" + iht_pad(GetCalendarMonth()) + "/" + iht_pad(GetCalendarDay()) + " " + iht_pad(GetTimeHour()) + ":" + iht_pad(GetTimeMinute()));
    WriteTimestampedLogEntry("=================");

    WriteTimestampedLogEntry("Date set to " + GetDateString());
    debug("Internal date is " + IntToString(GetCalendarYear()) + "/" + iht_pad(GetCalendarMonth()) + "/" + iht_pad(GetCalendarDay()) + " " + iht_pad(GetTimeHour()) + ":" + iht_pad(GetTimeMinute()));
produces this logging:

[Mon Jan  7 12:02:54] Loading Module: module000
[Mon Jan  7 12:02:54] Internal date is 1330/01/01 00:00
[Mon Jan  7 12:02:54] Date Args:  1359, 6, 6
[Mon Jan  7 12:02:54] Time Args:  18, 3, 0, 0
[Mon Jan  7 12:02:54] Setting date  to 1359/06/06 18:03
[Mon Jan  7 12:02:54] Setting date  to 1359/06/06 18:03
[Mon Jan  7 12:02:54] Internal date is 1359/06/06 19:00
I've checked that's it not overflowing or trying to set time backwards.. it's odd that I sent it 18:03, but it sets to 19:00. And the discrepancy is not always just one hour. Sometimes. it's 2 or 3 hours off. Or even 24+ hours off (adding the time bumps the day up, even through hours and minutes are both less than 24 and 60 respectively)

Comments

  • ELadnerELadner Member Posts: 8
    edited January 7
    Example module. (this module uses NWNX only for the NWNX_Time plugin)

  • ELadnerELadner Member Posts: 8
    Vanilla module (no NWNX required) attached.

    Check out this train wreck.. Note the odd incrementing of the minute (base 4?) and the rollover of the day at hour 14. What the heck?

    This code:
    
        int h;
        int l;
        for (h = 0; h < 2; h++) {
          for (l = 0; l < 60; l++) {
            SetTime(h, l, 0, 0);
            WriteTimestampedLogEntry(IntToString(h) + ", " + IntToString(l) + ", " + IntToString(GetCalendarYear()) + "/" + IntToString(GetCalendarMonth()) + "/" + IntToString(GetCalendarDay()) + " " + IntToString(GetTimeHour()) + ":" + IntToString(GetTimeMinute()));
          }
        }
    
    Produces this output:
    [Mon Jan  7 14:09:14] Loading Module: module001
    [Mon Jan  7 14:09:14] Internal date is 1330/1/1 0:0
    
    /* Note.. this is printing (hour), (minute), date after calling SetTime(h, m, 0, 0) */
    
    [Mon Jan  7 14:09:14] 0, 0, 1330/1/2 0:0
    [Mon Jan  7 14:09:14] 0, 1, 1330/1/2 0:1
    [Mon Jan  7 14:09:14] 0, 2, 1330/1/2 0:2
    [Mon Jan  7 14:09:14] 0, 3, 1330/1/2 0:3
    [Mon Jan  7 14:09:14] 0, 4, 1330/1/2 1:0
    [Mon Jan  7 14:09:14] 0, 5, 1330/1/2 1:1
    [Mon Jan  7 14:09:14] 0, 6, 1330/1/2 1:2
    [Mon Jan  7 14:09:14] 0, 7, 1330/1/2 1:3
    [Mon Jan  7 14:09:14] 0, 8, 1330/1/2 2:0
    [Mon Jan  7 14:09:14] 0, 9, 1330/1/2 2:1
    [Mon Jan  7 14:09:14] 0, 10, 1330/1/2 2:2
    [Mon Jan  7 14:09:14] 0, 11, 1330/1/2 2:3
    [Mon Jan  7 14:09:14] 0, 12, 1330/1/2 3:0
    [Mon Jan  7 14:09:14] 0, 13, 1330/1/2 3:1
    [Mon Jan  7 14:09:14] 0, 14, 1330/1/2 3:2
    [Mon Jan  7 14:09:14] 0, 15, 1330/1/2 3:3
    [Mon Jan  7 14:09:14] 0, 16, 1330/1/2 4:0
    [Mon Jan  7 14:09:14] 0, 17, 1330/1/2 4:1
    [Mon Jan  7 14:09:14] 0, 18, 1330/1/2 4:2
    [Mon Jan  7 14:09:14] 0, 19, 1330/1/2 4:3
    [Mon Jan  7 14:09:14] 0, 20, 1330/1/2 5:0
    [Mon Jan  7 14:09:14] 0, 21, 1330/1/2 5:1
    [Mon Jan  7 14:09:14] 0, 22, 1330/1/2 5:2
    [Mon Jan  7 14:09:14] 0, 23, 1330/1/2 5:3
    [Mon Jan  7 14:09:14] 0, 24, 1330/1/2 6:0
    [Mon Jan  7 14:09:14] 0, 25, 1330/1/2 6:1
    [Mon Jan  7 14:09:14] 0, 26, 1330/1/2 6:2
    [Mon Jan  7 14:09:14] 0, 27, 1330/1/2 6:3
    [Mon Jan  7 14:09:14] 0, 28, 1330/1/2 7:0
    [Mon Jan  7 14:09:14] 0, 29, 1330/1/2 7:1
    [Mon Jan  7 14:09:14] 0, 30, 1330/1/2 7:2
    [Mon Jan  7 14:09:14] 0, 31, 1330/1/2 7:3
    [Mon Jan  7 14:09:14] 0, 32, 1330/1/2 8:0
    [Mon Jan  7 14:09:14] 0, 33, 1330/1/2 8:1
    [Mon Jan  7 14:09:14] 0, 34, 1330/1/2 8:2
    [Mon Jan  7 14:09:14] 0, 35, 1330/1/2 8:3
    [Mon Jan  7 14:09:14] 0, 36, 1330/1/2 9:0
    [Mon Jan  7 14:09:14] 0, 37, 1330/1/2 9:1
    [Mon Jan  7 14:09:14] 0, 38, 1330/1/2 9:2
    [Mon Jan  7 14:09:14] 0, 39, 1330/1/2 9:3
    [Mon Jan  7 14:09:14] 0, 40, 1330/1/2 10:0
    [Mon Jan  7 14:09:14] 0, 41, 1330/1/2 10:1
    [Mon Jan  7 14:09:14] 0, 42, 1330/1/2 10:2
    [Mon Jan  7 14:09:14] 0, 43, 1330/1/2 10:3
    [Mon Jan  7 14:09:14] 0, 44, 1330/1/2 11:0
    [Mon Jan  7 14:09:14] 0, 45, 1330/1/2 11:1
    [Mon Jan  7 14:09:14] 0, 46, 1330/1/2 11:2
    [Mon Jan  7 14:09:14] 0, 47, 1330/1/2 11:3
    [Mon Jan  7 14:09:14] 0, 48, 1330/1/2 12:0
    [Mon Jan  7 14:09:14] 0, 49, 1330/1/2 12:1
    [Mon Jan  7 14:09:14] 0, 50, 1330/1/2 12:2
    [Mon Jan  7 14:09:14] 0, 51, 1330/1/2 12:3
    [Mon Jan  7 14:09:14] 0, 52, 1330/1/2 13:0
    [Mon Jan  7 14:09:14] 0, 53, 1330/1/2 13:1
    [Mon Jan  7 14:09:14] 0, 54, 1330/1/2 13:2
    [Mon Jan  7 14:09:14] 0, 55, 1330/1/2 13:3
    [Mon Jan  7 14:09:14] 0, 56, 1330/1/2 14:0
    [Mon Jan  7 14:09:14] 0, 57, 1330/1/2 14:1
    [Mon Jan  7 14:09:14] 0, 58, 1330/1/2 14:2
    [Mon Jan  7 14:09:14] 0, 59, 1330/1/2 14:3
    [Mon Jan  7 14:09:14] 1, 0, 1330/1/3 1:0
    [Mon Jan  7 14:09:14] 1, 1, 1330/1/3 1:1
    [Mon Jan  7 14:09:14] 1, 2, 1330/1/3 1:2
    [Mon Jan  7 14:09:14] 1, 3, 1330/1/3 1:3
    [Mon Jan  7 14:09:14] 1, 4, 1330/1/3 2:0
    [Mon Jan  7 14:09:14] 1, 5, 1330/1/3 2:1
    [Mon Jan  7 14:09:14] 1, 6, 1330/1/3 2:2
    [Mon Jan  7 14:09:14] 1, 7, 1330/1/3 2:3
    [Mon Jan  7 14:09:14] 1, 8, 1330/1/3 3:0
    [Mon Jan  7 14:09:14] 1, 9, 1330/1/3 3:1
    [Mon Jan  7 14:09:14] 1, 10, 1330/1/3 3:2
    [Mon Jan  7 14:09:14] 1, 11, 1330/1/3 3:3
    [Mon Jan  7 14:09:14] 1, 12, 1330/1/3 4:0
    [Mon Jan  7 14:09:14] 1, 13, 1330/1/3 4:1
    [Mon Jan  7 14:09:14] 1, 14, 1330/1/3 4:2
    [Mon Jan  7 14:09:14] 1, 15, 1330/1/3 4:3
    [Mon Jan  7 14:09:14] 1, 16, 1330/1/3 5:0
    [Mon Jan  7 14:09:14] 1, 17, 1330/1/3 5:1
    [Mon Jan  7 14:09:14] 1, 18, 1330/1/3 5:2
    [Mon Jan  7 14:09:14] 1, 19, 1330/1/3 5:3
    [Mon Jan  7 14:09:14] 1, 20, 1330/1/3 6:0
    [Mon Jan  7 14:09:14] 1, 21, 1330/1/3 6:1
    [Mon Jan  7 14:09:14] 1, 22, 1330/1/3 6:2
    [Mon Jan  7 14:09:14] 1, 23, 1330/1/3 6:3
    [Mon Jan  7 14:09:14] 1, 24, 1330/1/3 7:0
    [Mon Jan  7 14:09:14] 1, 25, 1330/1/3 7:1
    [Mon Jan  7 14:09:14] 1, 26, 1330/1/3 7:2
    [Mon Jan  7 14:09:14] 1, 27, 1330/1/3 7:3
    [Mon Jan  7 14:09:14] 1, 28, 1330/1/3 8:0
    [Mon Jan  7 14:09:14] 1, 29, 1330/1/3 8:1
    [Mon Jan  7 14:09:14] 1, 30, 1330/1/3 8:2
    [Mon Jan  7 14:09:14] 1, 31, 1330/1/3 8:3
    [Mon Jan  7 14:09:14] 1, 32, 1330/1/3 9:0
    [Mon Jan  7 14:09:14] 1, 33, 1330/1/3 9:1
    [Mon Jan  7 14:09:14] 1, 34, 1330/1/3 9:2
    [Mon Jan  7 14:09:14] 1, 35, 1330/1/3 9:3
    [Mon Jan  7 14:09:14] 1, 36, 1330/1/3 10:0
    [Mon Jan  7 14:09:14] 1, 37, 1330/1/3 10:1
    [Mon Jan  7 14:09:14] 1, 38, 1330/1/3 10:2
    [Mon Jan  7 14:09:14] 1, 39, 1330/1/3 10:3
    [Mon Jan  7 14:09:14] 1, 40, 1330/1/3 11:0
    [Mon Jan  7 14:09:14] 1, 41, 1330/1/3 11:1
    [Mon Jan  7 14:09:14] 1, 42, 1330/1/3 11:2
    [Mon Jan  7 14:09:14] 1, 43, 1330/1/3 11:3
    [Mon Jan  7 14:09:14] 1, 44, 1330/1/3 12:0
    [Mon Jan  7 14:09:14] 1, 45, 1330/1/3 12:1
    [Mon Jan  7 14:09:14] 1, 46, 1330/1/3 12:2
    [Mon Jan  7 14:09:14] 1, 47, 1330/1/3 12:3
    [Mon Jan  7 14:09:14] 1, 48, 1330/1/3 13:0
    [Mon Jan  7 14:09:14] 1, 49, 1330/1/3 13:1
    [Mon Jan  7 14:09:14] 1, 50, 1330/1/3 13:2
    [Mon Jan  7 14:09:14] 1, 51, 1330/1/3 13:3
    [Mon Jan  7 14:09:14] 1, 52, 1330/1/3 14:0
    [Mon Jan  7 14:09:14] 1, 53, 1330/1/3 14:1
    [Mon Jan  7 14:09:14] 1, 54, 1330/1/3 14:2
    [Mon Jan  7 14:09:14] 1, 55, 1330/1/3 14:3
    [Mon Jan  7 14:09:14] 1, 56, 1330/1/3 15:0
    [Mon Jan  7 14:09:14] 1, 57, 1330/1/3 15:1
    [Mon Jan  7 14:09:14] 1, 58, 1330/1/3 15:2
    [Mon Jan  7 14:09:14] 1, 59, 1330/1/3 15:3
    [Mon Jan  7 14:09:14] =================
    [Mon Jan  7 14:09:14] Date Args:  1559, 4, 16
    [Mon Jan  7 14:09:14] Internal date is 1559/4/16 15:3
    [Mon Jan  7 14:09:14] =================
    

Sign In or Register to comment.