Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin: When a script is loaded and immediately queries the GameDate, it receives a scenario-dependent, non-zero value. #12775

Open
Sadret opened this issue Aug 25, 2020 · 1 comment
Labels
plug-in Related to the plugin system of OpenRCT2.

Comments

@Sadret
Copy link
Contributor

Sadret commented Aug 25, 2020

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).
@Sadret 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
@tupaschoal tupaschoal added the plug-in Related to the plugin system of OpenRCT2. label Aug 25, 2020
@James103
Copy link
Contributor

James103 commented Jun 24, 2022

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plug-in Related to the plugin system of OpenRCT2.
Projects
None yet
Development

No branches or pull requests

3 participants