BL Coding unable to convert from "bool" to "System.Func<(bool, TaleWorlds.Localization.TextObject)>"

Users who are viewing this thread

AtiLin

Recruit
Мy first experience.
I do it according to the tutorial and i have problem.

Module.CurrentModule.AddInitialStateOption(new InitialStateOption("Message",
new TextObject("Message", null),
9990,
() => { InformationManager.DisplayMessage(new InformationMessage("Hello World!")); },
false));

Compiler Error CS1503 - unable to convert from "bool" to "System.Func<(bool, TaleWorlds.Localization.TextObject)>".


How to replace "false" with this "Func<(bool, TextObject)"?
 
C#:
Module.CurrentModule.AddInitialStateOption(new InitialStateOption("Message",
new TextObject("Message", null),
9990,
() => { InformationManager.DisplayMessage(new InformationMessage("Hello World!")); },
() => (false, new TextObject())));
 
Upvote 1

AtiLin

Recruit
Now the problem is after the build.
Apparently the tutorial was for older versions, but I can't figure it out myself yet.

error at startup - the application faced a problem.

bebug log
System.NullReferenceException
HResult=0x80004003
Message = Object reference not set to an instance of an object.
A source = TaleWorlds.MountAndBlade
Stack Trace:
at TaleWorlds.MountAndBlade.Module.InitializeSubModules()
at TaleWorlds.MountAndBlade.Module.LoadSubModules()
at TaleWorlds.MountAndBlade.Module.Initialize()


the code from the tutorial with the correction.
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
using TaleWorlds.Localization;
namespace ExampleModNameSpace
{
public class MySubModule : MBSubModuleBase
{
protected override void OnSubModuleLoad()
{
Module.CurrentModule.AddInitialStateOption(new InitialStateOption("Message",
new TextObject("Message", null),
9990,
() => { InformationManager.DisplayMessage(new InformationMessage("Hello World!")); },
() => (false, new TextObject())));
}
}
}
 
Upvote 0
Now the problem is after the build.
Apparently the tutorial was for older versions, but I can't figure it out myself yet.

error at startup - the application faced a problem.

bebug log
System.NullReferenceException
HResult=0x80004003
Message = Object reference not set to an instance of an object.
A source = TaleWorlds.MountAndBlade
Stack Trace:
at TaleWorlds.MountAndBlade.Module.InitializeSubModules()
at TaleWorlds.MountAndBlade.Module.LoadSubModules()
at TaleWorlds.MountAndBlade.Module.Initialize()


the code from the tutorial with the correction.
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
using TaleWorlds.Localization;
namespace ExampleModNameSpace
{
public class MySubModule : MBSubModuleBase
{
protected override void OnSubModuleLoad()
{
Module.CurrentModule.AddInitialStateOption(new InitialStateOption("Message",
new TextObject("Message", null),
9990,
() => { InformationManager.DisplayMessage(new InformationMessage("Hello World!")); },
() => (false, new TextObject())));
}
}
}
I tried this code and it works. I don't get any errors. Maybe the null reference exception is caused by something else on your end?
 
Last edited:
Upvote 0

AtiLin

Recruit
Apparently I made a mistake somewhere in the project settings. I've reassembled everything. It worked.

Thank you!)
 
Last edited:
Upvote 0
Top Bottom