gregdwilson Posted June 18, 2015 Share Posted June 18, 2015 I'm trying to use remainingtimeinphase from the clock component. Essentially, I need to be able to get use the time until morning (how much time night has left) inside of modmain but I can't seem to figure out the right syntax. Any help would be appreciated. Link to comment Share on other sites More sharing options...
DarkXero Posted June 18, 2015 Share Posted June 18, 2015 You can useGLOBAL.TheWorld.state.timeinphasethis returns a number between 0 and 1 depending on the position of the arrow.At the start of the night, it will return 0. In the middle, 0.5. In the end, 1. To know how many seconds passed since the start of the night, you can listen to the clocktick event. Or save the time when the night starts:-- We save time when night startsinst:WatchWorldState("startnight", function(inst) inst.time = GLOBAL.TheWorld.state.timeend)And given that we know the percentage of time passed, and when the night started, we can:a) Calculate the secs passedlocal function secs_passed_in_night_phase(inst) return GLOBAL.TheWorld.state.time - inst.timeendb) Calculate the secs leftlocal secs_left_in_night_phase(inst) return (1 - GLOBAL.TheWorld.state.timeinphase) * secs_passed_in_night_phase(inst) / GLOBAL.TheWorld.state.timeinphaseend Link to comment Share on other sites More sharing options...
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