Jump to content

Modding - GameHour.GetValue() Returning Zero


Recommended Posts

Posted (edited)

Hello!

I'm attempting to write a on-activate script but have run into a snag. The object is supposed to behave differently at different times of day so naturally, I tried using the GameHour.GetValue() and assigning it to a variable. This is what I've been working with:


 

Scriptname SCM_DAilyStart extends ObjectReference conditional

GlobalVariable Property GameHour auto
ObjectReference Property SCM_DailyActivate01REF Auto
ObjectReference Property SCM_DailyActivate02REF Auto
ObjectReference Property SCM_DailyActivate03REF Auto
ObjectReference Property SCM_DailyActivate04REF Auto
ObjectReference Property SCM_DailyActivate05REF Auto
Message Property SCM_DayStartMsg  Auto
Message Property SCM_DayStartDeniedMsg  Auto

Event OnActivate(ObjectReference akActionRef)
    int hour = GameHour.GetValue() as int
    Debug.Notification ( "GameTime: " + hour )
    if hour > 21 || hour < 5
        SCM_DayStartDeniedMsg.Show()
    else
        SCM_DailyActivate01REF.Enable()
        SCM_DailyActivate02REF.Enable()
        SCM_DailyActivate03REF.Enable()
        SCM_DailyActivate04REF.Enable()
        SCM_DailyActivate05REF.Enable()
        SCM_DayStartMsg.Show()
    endif
    
EndEvent

 

But I never get the else condition. The Debug indicates that the GameHour is always 0 when I activate the object this is attached to. This is on an ongoing game, in a new game the activation doesn't seem to work at all. Was wondering if someone had insight into why that is or why I always get GameHour 0? Thanks. And just to note I am assigning GameHour to the global in the CK.

Edited by Next_To_Nothing
Posted

A couple of things come to mind:

  1. In the in-game console: help GameTime 3
  2. Disable all mods (easy if you're on MO2) then do #1 above.
  3. Using dunBloatedManToggleBloodmoon.psc as an example, it seems this GV can be used to set the time of day. Thus the next question is, are you sure you in-game time is actually advancing, or is it always noon/midnight/whatever?
  4. The GameHour GV is defined as a float, thus you casting it to an int is a potential precision/data loss situation. I see the vanilla scripts use GetValueInt (which seems like it would be similar to what you're doing) however I'd personally be much more comfortable with retrieving it as a float and handling it like a float, instead of casting and hoping for the best. There's no reason why you couldn't do this in your code.
Posted

What you need is first

Int Function GetCurrentGameHour() Global
	Float GameTime
	GameTime = Utility.GetCurrentGameTime()
	GameTime -= Math.Floor(GameTime)
	GameTime *= 24
	Return GameTime As Int
EndFunction

Then you can use the function

Event OnActivate(ObjectReference akActionRef)
If (GetCurrentGameHour()<9) && (GetCurrentGameHour() >3)
	Debug.Notification("It is night")
Else
	Debug.Notification("It is day")
EndIf
EndEvent
	

 

Posted
On 5/24/2024 at 5:11 PM, DarkBlade13 said:

What you need is first

Int Function GetCurrentGameHour() Global
	Float GameTime
	GameTime = Utility.GetCurrentGameTime()
	GameTime -= Math.Floor(GameTime)
	GameTime *= 24
	Return GameTime As Int
EndFunction

Then you can use the function

Event OnActivate(ObjectReference akActionRef)
If (GetCurrentGameHour()<9) && (GetCurrentGameHour() >3)
	Debug.Notification("It is night")
Else
	Debug.Notification("It is day")
EndIf
EndEvent
	

 

 

Thank you! That did the trick. I did see GetCurrentGame time as an option but wasn't sure how to translate it into hours.

Posted
54 minutes ago, Next_To_Nothing said:

 

Thank you! That did the trick. I did see GetCurrentGame time as an option but wasn't sure how to translate it into hours.

 

Keep in mind that by using Utility.GetCurrentGameTime() you're just working around the issue of GameHour always returning 0. If another script is not functioning properly in the future, you need to remember this issue. Many vanilla scripts use this GV for instance.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...