Jump to content

ms_setmoonphase event incorrectly sets waning moon phases as waxing


Raw lettuce
  • Pending

Hello, I've found a bug in components/clock.lua related to how moon phases are set via the ms_setmoonphase event.
When using the ms_setmoonphase event to set a specific waning moon phase (e.g., a waning three-quarter moon), the game incorrectly sets it to the corresponding waxing phase instead. The iswaxing = false parameter is effectively ignored for certain phases.

To my mind, the root cause is in the OnSetMoonPhase function in components/clock.lua. The for loop that searches for the correct index in the MOON_PHASE_CYCLES array starts its search at the wrong position for waning phases.

The line in question is:

Quote

for i = (data.iswaxing and 1 or #MOON_PHASE_CYCLES/2), #MOON_PHASE_CYCLES do

The MOON_PHASE_CYCLES array has 20 elements. The waxing period is defined by indices 1 through 10. When data.iswaxing is false, the loop starts at index 10 (#MOON_PHASE_CYCLES/2).

The value at MOON_PHASE_CYCLES[10] corresponds to the "threequarter" phase, but it is the last day of the waxing three-quarter moon. The loop finds this match immediately, sets the internal cycle day to 10, and GetMoonPhase() subsequently (and correctly, given the index) determines the phase is waxing because 10 <= 10.

That’s how I understand it – hope I didn’t mess up and made myself clear!


Steps to Reproduce

TheWorld:PushEvent("ms_setmoonphase", {moonphase = “threequarter”, iswaxing = false})

The GetDebugString of components/clock.lua will show something like: 
 

Quote

10 night: 175.19 : 16.00 (moon cycle: 10)   

And the Dump() result:

Quote

[01:42:18]: Time of Day:    305.01388549805    
[01:42:18]: segs in day       0    
[01:42:18]: segs in dusk      0    
[01:42:18]: segs in night     16    
[01:42:18]: cycles     9    
[01:42:18]: phase     night    
[01:42:18]: moonphase2     threequarter    
[01:42:18]: moonwaxing     true    
[01:42:18]: totaltimeinphase     480    
[01:42:18]: remainingtimeinphase     174.98611450195    
[01:42:18]: total segs phase     16    
[01:42:18]: remaining segs inphase     5.8328704833984    
[01:42:18]: Time Until Night:    174.98611450195    5.8328704833984    

 




User Feedback


There are no comments to display.



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

×
  • Create New...