C
C#2y ago
ana

❔ ✅ 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
phaseshift2y ago
You're probably adding features to a different feature manager instance
Matt
Matt2y ago
you never call init() too in your example code, at least
ana
anaOP2y ago
init() is called when the program opens
phaseshift
phaseshift2y ago
Show the code calling init() and where the features are added
ana
anaOP2y ago
phaseshift
phaseshift2y ago
This
ana
anaOP2y ago
how do i not add features to a different feature manager instance
phaseshift
phaseshift2y ago
Use one instance Pass it around
ana
anaOP2y ago
oh that worked thanks are these closed somehow or
phaseshift
phaseshift2y ago
!Solved I think You have to do it. Or maybe "closed" !close
Accord
Accord2y 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.
Want results from more Discord servers?
Add your server