Jump to content

Question about keeping track of time in game.


ErianDragonborn

Recommended Posts

I have to enable an x-marker after a certain time (2 in-game days or a real-life hour or so after activating a lever) and I have a few methods. I am not sure however which one I could best use.

 

1:
I know I can fire a script with the lever and use 'Utility.wait()'. This will register real time and will pause when in a menu.

- Will this keep ticking even if you are in a different cell / location?

EDIT: - also, will this reset every time the script is fired again?
i.e. I activate the lever and check that I want to enable marker A
Then the 'wait' thing kicks in and waits for 60 seconds
After 30 seconds I pull the lever again and choose to enable marker B
What will happen? Will A be enabled after 30 seconds and 30 seconds later B? Or will B be enabled after 60 seconds, or 30 seconds? Or will A be enabled?

 

2:

There is a way to use in-game time too, I can save the time at which the lever was pulled and check the current time with that time.

- Is there a way to do it like this without registering for update? Since I think that would take quite some computing power.

 

3:

Are there methods I have missed?
These are by using Papyrus, but maybe there also is a way using the built-in logic system?

Edited by ErianDragonborn
Link to comment
Share on other sites

Wait is almost always a bad choice, especially if it's a long delay like you describe here.

 

RegisterForSingleUpdateGameTime is designed for exactly this sort of situation (and requires less resources that any other solution).

 

The answer to your original question is to simply use a RegisterForSingleUpdateGameTime when the level is pulled and then let the OnUpdate event finish the enable.

 

But your additional question about multiple markers and pulling the lever multiple times raise problems with different solutions depending on how you want it to work.

 

If you do the simple case of registering on the OnActivate and enabling on the OnUpdate then pulling the lever a second time will reset and restart the timer with a fresh count-down. To get around that you would probably want to use a script state so that any lever pulls are ignored while the update is in progress.

 

If you want a single lever to trigger updates on multiple objects you run into the problem that a script can only be registered for one game update at a time. But the way around that is to put the script implementing the delay on the markers not the lever.

 

Here's one way it could be done. First put this script on each of the markers then in the lever script you simply need to use "MyMarker.Activate(self)" instead of "MyMarker.Enable()". It's possible to get fancier but with this script on the markers each marker will have its own timer and which will trigger 2 days after the first time it's activated even if it's activated multiple times.

ScriptName Delayed2DayEnable extends ObjectReference

Event OnActivate(ObjectReference akActionRef)
    GoToState("Delayed")
    RegisterForSingleUpdateGameTime(48.0) ; 48 hours is 2 days
EndEvent

Event OnUpdate()
    GoToState("")
    Enable()
EndEvent

State Delayed
Event OnActivate(ObjectReference akActionRef)
    ; empty event here prevents resetting the timer if it's already running
EndEvent
EndState
Link to comment
Share on other sites

@cdcooley
Thanks! It was working with 'wait' but I already had my doubt on whether that was a stable solution.
I will use RegisterForSingleUpdateGameTime.
There is one thing I still need to know (but can probably test it):
Does it still update, even if the cell is not loaded?
edit: it is fine if it updates as soon as the cell is loaded.

Edited by ErianDragonborn
Link to comment
Share on other sites

  • Recently Browsing   0 members

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