Replies: 4 (Who?), Viewed: 108 times.
Virtual gardener
staff: administrator
Original Poster
#1 Old 29th Jul 2022 at 12:08 PM
Default Listening in on Substate changing causes infinite load
Hey all!

For the mod I'm working on, I have to make sure that the code will trigger on both Playflow and Edit town. I noticed that EA has an event for this and decided to go through with this.

Now, i've only been able to trigger this successfully once, but somehow now, every time I want to load a new save, it simply infinitely loads. The bar is almost full, which to me indicates that something has gone wrong and cannot get to the "OnWorldLoadFinished" state.

Here's the code:

Code:
		static RPGManagerUtil()
		{
			World.sOnWorldLoadFinishedEventHandler += OnWorldLoaded;
			World.sOnWorldLoadStartedEventHandler += new EventHandler(OnWorldLoadStarted);
			World.sOnWorldQuitEventHandler += new EventHandler(OnWorldQuit);

// My previous approach was simply doing the GameStateChanging event here:
// Responder.Instance.GameStateChanging += OnGameStateChanging;

		}

		public static void OnWorldQuit(object sender, EventArgs e)
        {
			Responder.Instance.GameStateChanging -= OnGameStateChanging;
		}
		public static void OnWorldLoadStarted(object sender, EventArgs e)
        {
			Responder.Instance.GameStateChanging += OnGameStateChanging;
		}

		public static void OnGameStateChanging(Responder.GameSubState previousState, Responder.GameSubState newState)
		{
print("In Game State!");
}


I really can't see a reason it just flat out doesn't want to load, unless I comment out the OnGameStateChanging call... which again is odd, because it used to work :p

I've also wrapped around a try/catch once around the part where I assign my event (In the catch, i'd just opt out of the function), hoping that will help, but that didn't seem to do anything either.
Advertisement
Field Researcher
#2 Old 29th Jul 2022 at 2:03 PM
Hanging on load like that is usually caused by an unhandled exception before the game reaches InWorldState.

If you have NRaas Traveler installed, it should log whatever's happening to a script error and force the game to continue past the load screen. That way, you can at least get a better idea of what's going on.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Virtual gardener
staff: administrator
Original Poster
#3 Old 29th Jul 2022 at 2:23 PM
Quote:
Originally Posted by gamefreak130
Hanging on load like that is usually caused by an unhandled exception before the game reaches InWorldState.

If you have NRaas Traveler installed, it should log whatever's happening to a script error and force the game to continue past the load screen. That way, you can at least get a better idea of what's going on.


That's the weird thing, Nraas is unable to catch it either. However, I've decided to go with a slightly different approach, which is by using the eventlistener and that seems to do the trick!

Code:
		static void OnWorldLoaded(object sender, EventArgs e)
{
			sSubStateListener = EventTracker.AddListener(EventTypeId.kEnterInWorldSubState, new ProcessEventDelegate(OnGameStateChanging));
}



However, since I want to access the Bin sims in edit Town/playflow, it seems to think it's empty? I'm thinking it's because kEnterInWorldSubstate's event fires quicker than the ExportContents bin can actually repopulate. (I'm really just going off that thought due to the fact that my function fires even before the UI with moving/choosing households has even been attached on the screen)

Code:
				List<UIBinInfo> uiInfo1 = BinCommon.GetInWorldHouseholdBinInfoList();
				List<UIBinInfo> uiInfo2 = BinCommon.GetGameBinInfoList();

				print("UI info1: " + uiInfo1.Count.ToString()); // 25, but returns just the sims in town, not bin sims
				print("UI info2: " + uiInfo2.Count.ToString()); // 0
				print("Bin Singleton: " + Bin.Singleton.Households.Count.ToString()); // 0

				List<IExportBinContents> mExportBin = Responder.Instance.BinModel.ExportBinContents; 

				if (mExportBin != null && mExportBin.Count > 0)
				{
					print("BinModel Export: " + mExportBin.Count.ToString()); // 0
				}
                else
                {
					print("Bin Model Export bin is empty");
                }


				if (BinModel.Singleton != null && BinModel.Singleton.mExportBin != null)
				{
					print("Bin Export: " + BinModel.Singleton.mExportBin.Count.ToString()); // 0

				}
				else
				{
					print("Export bin is empty");
				}


And I don't think I'll be able to use an Alarm to wait a few ticks before firing the event, given that in edit town mode or playflow the game is technically paused.
Field Researcher
#4 Old 29th Jul 2022 at 3:22 PM
I think the ExportBinContents is mainly what you're looking for here. The GameBin is just the temporary clipboard that is used when e.g. evicting households.

You're correct that the export bin contents are only populated once the Edit Town/Play Flow UI is initialized, whereas the kEnterInWorldSubState event is fired before this initialization occurs. What I've done to work around this is to simply add a Simulator task in the event listener instead.

Code:
private static ListenerAction OnGameStateChanging(Event e)
{
    Simulator.AddObject(new OneShotFunctionTask(DoExportBinThings));
    return ListenerAction.Keep;
}

private static void DoExportBinThings()
{
    // Your code, probably with a more descriptive method name 
}


Then, all of the synchronous code for the state transition (including UI and export bin initialization) will be guaranteed to run before the game comes back around to run the task.

"The Internet is the first thing that humanity has built that humanity doesn't understand, the largest experiment in anarchy that we have ever had." - Eric Schmidt

If you enjoy the mods I put out, consider supporting me on patreon: www.patreon.com/Gamefreak130
Virtual gardener
staff: administrator
Original Poster
#5 Old 30th Jul 2022 at 9:33 AM Last edited by Lyralei : 30th Jul 2022 at 12:54 PM.
Hrm not a bad approach actually, I think indeed this should do it. Because, currently it gets triggered so quickly, that none of the sims are properly instantiated either Let me give this a try! Thank you!

EDIT: Woooh! That did the trick! And fixed a few other problems I had with things not being done loading yet Thank you again!
Back to top