Talk:GetPCSleepHours

There are no discussions on this page.

Has anyone been able to get this to work? I've tried it every way I can think of and can't get it to return anything. The fact that it doesn't seem to have been used by Betheseda doesn't bode well. So if anyone needs a workaround here's one I prepared earlier:


short asleep
short dayslept
short dayawoke
short dayspassed
float curtime
float startsleep
float endsleep
float timeslept

Begin MenuMode 1012 ; this encompasses the wait and sleep menus, so:

if IsPCSleeping == 1 ; this allows differentiation between wait and sleep
   set asleep to 1
   set dayslept to GameDaysPassed
   set startsleep to curtime
endif

End

Begin GameMode

; fix the 24 hour clock, so that it can be used for subtracting
if GameHour != 0
   set curtime to GetCurrentTime
else
   set curtime to GetCurrentTime + 24
endif

; now find out how long slept for
if asleep == 1 ; ie has the player been to the sleep menu since last in GameMode
   set dayawoke to GameDaysPassed ; finds day player left sleep menu
   set dayspassed to dayawoke - dayslept
   set endsleep to curtime ; finds the time the player left the sleep menu
   ; now calculate how long player has slept. This is somewhat over specified
   ; in that I don't think it's possible to sleep for more than 24 hours...
   set timeslept to ( dayspassed * 24 - startsleep ) + endsleep
   ; prepare to reset next time script runs
   set asleep to 0
else
   set timeslept to 0
endif
End

Darknel 14:04, 24 August 2006 (EDT)

tejón 01:47, 9 November 2008 (EST): The problem is that as the timer counts down, GetPCSleepHours continues to report the current time remaining. If you're only trying to detect sleep, detect IsPCSleeping as detailed above, then set a flag and check GetPCSleepHours once. After you use the value, reset the flag. If you want to detect both rest and sleep, I think Darknel's method (omitting the IsPCSleeping check) is the only reliable way... with nothing else to flag for, you'd have to keep reading values until menumode ends and use the highest one. Unfortunately, sliding the timer up and down changes the value as you do it, so a "max value" script can be fooled by setting a high value, then reducing it before pressing Wait.

Return to "GetPCSleepHours" page.