Question LoadStageChanged problem

idermailer

Cowpoke
I'm making a mod. I got NotImplementedException, but I cannot guess the cause at all. I made sure using .NET 5.0 and latest SMAPI(3.15.1). Can you give me a hint please?

Here is the ModEntry.cs:
C#:
using System;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Enums;
using StardewModdingAPI.Events;
using StardewModdingAPI.Utilities;
using StardewValley;

namespace RandomStartDay
{
    /// <summary>The mod entry point.</summary>
    public class ModEntry : Mod
    {
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            helper.Events.Specialized.LoadStageChanged += this.Specialized_LoadStageChanged;
        }

        private void Specialized_LoadStageChanged(object sender, LoadStageChangedEventArgs e)
        {
            if (e.NewStage == LoadStage.CreatedBasicInfo)
            {
                Game1.currentSeason = "fall";
                Game1.dayOfMonth = 3;
            }
            throw new NotImplementedException();
        }
    }
}
and i got this:
Code:
[14:05:23 ERROR Random Start Day] This mod failed in the Specialized.LoadStageChanged event. Technical details:
NotImplementedException: The method or operation is not implemented.
   at RandomStartDay.ModEntry.Specialized_LoadStageChanged(Object sender, LoadStageChangedEventArgs e) in C:\Users\IN\source\repos\RandomStartDay\RandomStartDay\ModEntry.cs:line 31
   at StardewModdingAPI.Framework.Events.ManagedEvent`1.Raise(TEventArgs args) in SMAPI\Framework\Events\ManagedEvent.cs:line 101
and here is the SMAPI log:
https://smapi.io/log/75ca6e77944643a0a53d36086ad1d860
 

Mizzion

Tiller
Not sure why you're using the specialized event. I assume you're trying to make it Fall day 3 on save creation? If so, there's an event for when a save if created.

Save Created Event:
Code:
Helper.Events.GameLoop.SaveCreated
As for your error, It looks like you're always throwing the exception.
Code:
NotImplementedException
The way your code is now it does the following.

1. Checks to see if the new stage is "CreatedBasicInfo" If it finds the stage, it changes the season and day.
2. Then it throws the NotImplementedException (It will be thrown even if it finds the Stage).

What you need to do if you want to keep using the specialized, which I advise against ( We try to use the normal events if they are available. ) , is use an
Code:
else
statement.

Example.

Code:
if (e.NewStage == LoadStage.CreatedBasicInfo)
            {
                Game1.currentSeason = "fall";
                Game1.dayOfMonth = 3;
            }
else
           {
              Throw your exception here.  Or just leave out the else and remove the throw exception since SMAPI won't do anything if the if statement fails.
           }
If you want more info on changing the day, You can check out the following mod, it allows the user to change the time/date CJBCheat Menu Source Code
 
Last edited:

idermailer

Cowpoke
Not sure why you're using the specialized event. I assume you're trying to make it Fall day 3 on save creation? If so, there's an event for when a save if created.

Save Created Event:
Code:
Helper.Events.GameLoop.SaveCreated
As for your error, It looks like you're always throwing the exception.
Code:
NotImplementedException
The way your code is now it does the following.

1. Checks to see if the new stage is "CreatedBasicInfo" If it finds the stage, it changes the season and day.
2. Then it throws the NotImplementedException (It will be thrown even if it finds the Stage).

What you need to do if you want to keep using the specialized, which I advise against ( We try to use the normal events if they are available. ) , is use an
Code:
else
statement.

Example.

Code:
if (e.NewStage == LoadStage.CreatedBasicInfo)
            {
                Game1.currentSeason = "fall";
                Game1.dayOfMonth = 3;
            }
else
           {
              Throw your exception here.  Or just leave out the else and remove the throw exception since SMAPI won't do anything if the if statement fails.
           }
If you want more info on changing the day, You can check out the following mod, it allows the user to change the time/date CJBCheat Menu Source Code
Thank you! I didn't know what is 'throw'
 
Top