C
C#16mo ago
nukkkiz

❔ ✅ Using a list

I am writing a program in which you can save configurations, which would save if a specific feature is enabled, and if it is, write "whatever=true".
public class ConfigManager
{
FeatureManager featureManager = new FeatureManager();
StreamWriter sw = new StreamWriter(ConfigFile);

public void writeConfig()
{
foreach (Feature feature in featureManager.getRegistered())
{
sw.WriteLine(feature.getName() + "=" + feature.isEnabled());
}
}
}
public class ConfigManager
{
FeatureManager featureManager = new FeatureManager();
StreamWriter sw = new StreamWriter(ConfigFile);

public void writeConfig()
{
foreach (Feature feature in featureManager.getRegistered())
{
sw.WriteLine(feature.getName() + "=" + feature.isEnabled());
}
}
}
I am using this code to try and write text to a config file, and ConfigFile variable is a path. FeatureManager code:
public class FeatureManager
{
public List<Feature> registered = new List<Feature>();

public void init()
{
register(new AutoTyper());
register(new AntiLag());
register(new AntiMail());
}

protected void register(Feature feature)
{
registered.Add(feature);
}

public List<Feature> getRegistered()
{
return registered;
}
}
public class FeatureManager
{
public List<Feature> registered = new List<Feature>();

public void init()
{
register(new AutoTyper());
register(new AntiLag());
register(new AntiMail());
}

protected void register(Feature feature)
{
registered.Add(feature);
}

public List<Feature> getRegistered()
{
return registered;
}
}
And a feature:
public class AutoTyper : Feature
{

public AutoTyper() : base("AutoTyper", "Automatically type stuff", Category.Casino) { }
// ^ NAME ^ DESCRIPTION ^ CATEGORY

// Here would be the feature's actual feature. For this, unneeded.
}
public class AutoTyper : Feature
{

public AutoTyper() : base("AutoTyper", "Automatically type stuff", Category.Casino) { }
// ^ NAME ^ DESCRIPTION ^ CATEGORY

// Here would be the feature's actual feature. For this, unneeded.
}
This code has no errors, but the items (features) in the registered List aren't recognized in the writeConfig method. (Meaning, when writing config it thinks there is no items, even though they were added) The output i want into the ConfigFile:
AutoTyper=true
AntiLag=true //these don't actually have to be true, but an output like this depending whether they are enabled or not
AntiMail=true
AutoTyper=true
AntiLag=true //these don't actually have to be true, but an output like this depending whether they are enabled or not
AntiMail=true
Hopefully this is understandable, and someone can help :D
11 Replies
phaseshift
phaseshift16mo ago
You're probably adding features to a different feature manager instance
Matt
Matt16mo ago
you never call init() too in your example code, at least
nukkkiz
nukkkiz16mo ago
init() is called when the program opens
phaseshift
phaseshift16mo ago
Show the code calling init() and where the features are added
nukkkiz
nukkkiz16mo ago
phaseshift
phaseshift16mo ago
This
nukkkiz
nukkkiz16mo ago
how do i not add features to a different feature manager instance
phaseshift
phaseshift16mo ago
Use one instance Pass it around
nukkkiz
nukkkiz16mo ago
oh that worked thanks are these closed somehow or
phaseshift
phaseshift16mo ago
!Solved I think You have to do it. Or maybe "closed" !close
Accord
Accord16mo ago
Closed! Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.