You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue: When a script is loaded and immediately queries the GameDate, it receives a scenario-dependent, non-zero value.
Solution:
Reset the scenario date before the plugin gets loaded.
Add a scenario.loaded hook. (I personally favor this solution, as it also solves other problems / improves other use cases).
The text was updated successfully, but these errors were encountered:
Sadret
changed the title
Plugin API: Scripts will not be re-initialised when a new scenario is loaded from within a running scenario.
Plugin: When a script is loaded and immediately queries the GameDate, it receives a scenario-dependent, non-zero value.
Aug 25, 2020
Add a scenario.loaded hook. (I personally favor this solution, as it also solves other problems / improves other use cases)
This is already implemented as map.change and map.changed in #16707.
However, the bug still occurs with the following plugin script:
registerPlugin({name: 'Testing 1',version: '1.0',authors: [''],type: 'intransient',licence: 'MIT',main: function(){context.subscribe('map.changed',function(){console.log("");console.log("The date is: ");console.log("Day "+date.day+", Month "+date.month+", Year "+date.year);console.log("("+date.ticksElapsed+" ticks elapsed)");});console.log("Test plugin initialized!");}});
With the above plugin loaded, starting OpenRCT2 v0.4.0-256-gfb7be45 (fb7be45 on develop) provided by GitHub, loading Forest Frontiers, then exiting to main menu and waiting a few minutes, I get the following output in the terminal:
'Test plugin initialized!'
''
'Park: Forest Frontiers'
'The date is: Day 23, Month 1, Year 302'
'(86541 ticks elapsed)'
''
'Park: Ancient Worlds'
'The date is: Day 1, Month 0, Year 1'
'(39480956 ticks elapsed)'
''
'Park: Le Jardin d'Eden'
'The date is: Day 24, Month 1, Year 302'
'(1645808 ticks elapsed)'
''
'Park: Evergreen Gardens'
'The date is: Day 16, Month 4, Year 13'
'(32123188 ticks elapsed)'
''
'Park: Leafy Lake'
'The date is: Day 23, Month 0, Year 246'
'(115457 ticks elapsed)'
''
...
This means when a scenario or park is loaded, by the time map.changed is called, the GameDate's ticksElapsed would have already been reset to the value from the new park, but the day, month, and year values are still retained from the old park.
Issue: When a script is loaded and immediately queries the GameDate, it receives a scenario-dependent, non-zero value.
Solution:
The text was updated successfully, but these errors were encountered: