FiftyTifty
FiftyTifty
CC#
Created by FiftyTifty on 4/4/2025 in #help
✅ Creating a single global object that can be accessed by other classes?
I'm someone who comes from using Pascal and Lua, so bear with me here. I want to create a single nested list with custom properties, which I can then iterate through. But it's not intuitive how we actually do that. To demonstrate, here is a snippet of the code I'm working on for Bannerlord:
C#
namespace TeachSpouses
{

public class tsCharacterToTeach
{
public Hero Student;
public int NumLevelsCanBeTaught;
}

public class tsListCharactersToTeach
{
public SkillObject Skill;
public List<tsCharacterToTeach> Students;
}

public class tsClassroom
{
public List<tsListCharactersToTeach> Teaching;
}

//...bunch of other classes
public class Util
{

public static bool bFoundSpousesExpanded;
public static void ShowMessage(string strToShow)
{

InformationManager.DisplayMessage(new InformationMessage("TeachSpouses - " + strToShow));

}
//..Even more classes
C#
namespace TeachSpouses
{

public class tsCharacterToTeach
{
public Hero Student;
public int NumLevelsCanBeTaught;
}

public class tsListCharactersToTeach
{
public SkillObject Skill;
public List<tsCharacterToTeach> Students;
}

public class tsClassroom
{
public List<tsListCharactersToTeach> Teaching;
}

//...bunch of other classes
public class Util
{

public static bool bFoundSpousesExpanded;
public static void ShowMessage(string strToShow)
{

InformationManager.DisplayMessage(new InformationMessage("TeachSpouses - " + strToShow));

}
//..Even more classes
I only need one instance of tsClassroom, and I'll handle clearing it out and refilling it. But a single instance would be a public static, which can't have objects assigned to it right? public static List<tsClassroom> = new List<tsClassroom> is not supported in C#, so I'm a bit lost, even if it's obvious to others 🐤
43 replies
CC#
Created by FiftyTifty on 3/28/2025 in #help
How to access functions in another class in the same namespace?
No description
9 replies