Next_To_Nothing Posted May 24, 2024 Posted May 24, 2024 (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 May 24, 2024 by Next_To_Nothing
traison Posted May 24, 2024 Posted May 24, 2024 A couple of things come to mind: In the in-game console: help GameTime 3 Disable all mods (easy if you're on MO2) then do #1 above. 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? 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.
DarkBlade13 Posted May 24, 2024 Posted May 24, 2024 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
Next_To_Nothing Posted May 26, 2024 Author Posted May 26, 2024 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. 1
traison Posted May 26, 2024 Posted May 26, 2024 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now