C
C#16mo ago
TerraReturns

Unclear class creation

how would i go about resolving this error? This is what im getting:
Error while compiling: IslandPatrol.cs(80,17): error CS0246: The type or namespace name `PluginConfig' could not be found. Are you missing an assembly reference?
Error while compiling: IslandPatrol.cs(80,17): error CS0246: The type or namespace name `PluginConfig' could not be found. Are you missing an assembly reference?
I believe I just need to define Plugin Config right? What would I need to do?
46 Replies
Kouhai
Kouhai16mo ago
Well where do you use PluginConfig?
ero
ero16mo ago
How are you compiling, also?
TerraReturns
TerraReturnsOP16mo ago
I'm using it in the creation of a config file, the only issue is that the plugin won't load if I don't define the PluginConfig class Oxide compiler for rust
Kouhai
Kouhai16mo ago
They upload the cs file to a server and it compiles it
TerraReturns
TerraReturnsOP16mo ago
it compiles C# 4.0 i believe
Kouhai
Kouhai16mo ago
So you have the PluginConfig defiend but you can't reference it?
TerraReturns
TerraReturnsOP16mo ago
it's not defined at all which i had just recently noticed but i dont know how to define it i know how to make a class but i'm not sure what i put within the brackets of a class fopr this specific thing
Jimmacle
Jimmacle16mo ago
that would be based on how it's used in the rest of your plugin code like i said in the other channel, seeing actual code would make this easier
TerraReturns
TerraReturnsOP16mo ago
yeah i was about to gimme a sec
Jimmacle
Jimmacle16mo ago
i find it odd that you have code that uses a class that you haven't written yet
TerraReturns
TerraReturnsOP16mo ago
I'm reading documentation on how to add a config file but either I didn't see where to write a class or it's not included im really new to C# and development in general
protected override void LoadDefaultConfig()
{
// Default configuration values
LogWarning("Creating a new configuration file");
Config["NumberOfHelicopters"] = 10;
Config["NumberOfCH47s"] = 4;
Config["NumberOfF15s"] = 4;
Config["PatrolHeliSpawnTime"] = 5.0;
Config["CH47SpawnDelay"] = 10.0;
Config["F15SpawnInterval"] = 2.7;
}

private void SaveConfig()
{
Config.WriteObject(config, true);
}

private void Init()
{
LoadDefaultConfig();
LoadConfigValues();

// Schedule event check
timer.Every(60, CheckEventStatus);

// Initialize other variables...
}

private PluginConfig config;


private void Init()
{
config = Config.ReadObject<PluginConfig>();
}


protected override void LoadDefaultConfig()
{
Config.WriteObject(GetDefaultConfig(), true);
}


private PluginConfig GetDefaultConfig()
{
return new PluginConfig
{

numberOfHelicopters = Config.Get<int>("NumberOfHelicopters"),
numberOfCH47s = Config.Get<int>("NumberOfCH47s"),
numberOfF15s = Config.Get<int>("NumberOfF15s"),
patrolHeliSpawnTime = Config.Get<float>("PatrolHeliSpawnTime"),
ch47SpawnDelay = Config.Get<float>("CH47SpawnDelay"),
f15SpawnInterval = Config.Get<float>("F15SpawnInterval"),

};
}
protected override void LoadDefaultConfig()
{
// Default configuration values
LogWarning("Creating a new configuration file");
Config["NumberOfHelicopters"] = 10;
Config["NumberOfCH47s"] = 4;
Config["NumberOfF15s"] = 4;
Config["PatrolHeliSpawnTime"] = 5.0;
Config["CH47SpawnDelay"] = 10.0;
Config["F15SpawnInterval"] = 2.7;
}

private void SaveConfig()
{
Config.WriteObject(config, true);
}

private void Init()
{
LoadDefaultConfig();
LoadConfigValues();

// Schedule event check
timer.Every(60, CheckEventStatus);

// Initialize other variables...
}

private PluginConfig config;


private void Init()
{
config = Config.ReadObject<PluginConfig>();
}


protected override void LoadDefaultConfig()
{
Config.WriteObject(GetDefaultConfig(), true);
}


private PluginConfig GetDefaultConfig()
{
return new PluginConfig
{

numberOfHelicopters = Config.Get<int>("NumberOfHelicopters"),
numberOfCH47s = Config.Get<int>("NumberOfCH47s"),
numberOfF15s = Config.Get<int>("NumberOfF15s"),
patrolHeliSpawnTime = Config.Get<float>("PatrolHeliSpawnTime"),
ch47SpawnDelay = Config.Get<float>("CH47SpawnDelay"),
f15SpawnInterval = Config.Get<float>("F15SpawnInterval"),

};
}
Jimmacle
Jimmacle16mo ago
and the documentation doesn't provide you an actual implementation of this class?
Jimmacle
Jimmacle16mo ago
the definition is basically this part where you can see the field names and types that this code expects the class to have
TerraReturns
TerraReturnsOP16mo ago
i don't think so, i can provide the link to the docs bc i might be overlooking
Jimmacle
Jimmacle16mo ago
so you'd want to define a PluginConfig with those 6 properties and the types in the <> brackets
TerraReturns
TerraReturnsOP16mo ago
okay, copy + paste but in a new class
Jimmacle
Jimmacle16mo ago
not quite copy and paste
TerraReturns
TerraReturnsOP16mo ago
elaborate
Jimmacle
Jimmacle16mo ago
you can just infer how the class should look based on how it's used in my screenshot you still have to define the actual fields/properties that code initializes the object by setting those 6 properties, so they need to exist in the class definition
TerraReturns
TerraReturnsOP16mo ago
okay so i need to define each line but they should be their default values? I dont think im understanding correctly
Jimmacle
Jimmacle16mo ago
it doesn't look like it matters whether you set defaults or not in your class because this code always sets them from whatever Config is
TerraReturns
TerraReturnsOP16mo ago
okay
Jimmacle
Jimmacle16mo ago
as an example a class with just the first property would look like
public class PluginConfig
{
public int numberOfHelicopters { get; set; }
}
public class PluginConfig
{
public int numberOfHelicopters { get; set; }
}
TerraReturns
TerraReturnsOP16mo ago
alright i'll give this a shot and let you know what happens this is giving me errors
SinFluxx
SinFluxx16mo ago
Don't add those commas in
TerraReturns
TerraReturnsOP16mo ago
so i dont need any symbols to separate them
SinFluxx
SinFluxx16mo ago
No
TerraReturns
TerraReturnsOP16mo ago
oh i dont lol ok thx
SinFluxx
SinFluxx16mo ago
Where are you defining it, I can't see?
TerraReturns
TerraReturnsOP16mo ago
for (int i = 0; i < numberOfF15s; i++)
for (int i = 0; i < numberOfF15s; i++)
does that not define it or something
SinFluxx
SinFluxx16mo ago
that's not defining it, that's using it
TerraReturns
TerraReturnsOP16mo ago
it was working perfectly earlier so its confusing oh ok
SinFluxx
SinFluxx16mo ago
int numberOfF15s = 1 would be an example of defining (declaring and initializing) it
TerraReturns
TerraReturnsOP16mo ago
alr so i should declare this in the void of SpawnF15s, correct
SinFluxx
SinFluxx16mo ago
in the void?
TerraReturns
TerraReturnsOP16mo ago
the private void whatever its called ok i put it there i'll let the server compile and see what it thinks oh yeah it worked thanks
SinFluxx
SinFluxx16mo ago
Well, private void SpawnF15s is a method signature, then you have {} to go around the method body, so I assume what you mean is you're putting it in the method body
TerraReturns
TerraReturnsOP16mo ago
yeah lol idk what its called
SinFluxx
SinFluxx16mo ago
depends how much you're looking to do with c#/programming overall but it might be an idea to get to grips with the fundamentals first!
TerraReturns
TerraReturnsOP16mo ago
yeah i really just started this project today with no knowledge of C# lmao
SinFluxx
SinFluxx16mo ago
Definitely feels a bit like running before you can walk
TerraReturns
TerraReturnsOP16mo ago
it reads like python tbh it looks similar to me but i only know a bit yeah but it was a fun day especially when it just starts working after so much trial and error
SinFluxx
SinFluxx16mo ago
but do you understand all the reasons why it didn't work, and all the things that then were changed to make it work?
TerraReturns
TerraReturnsOP16mo ago
yeah i do the way you explained it was helpful
SinFluxx
SinFluxx16mo ago
Fair enough, I think you've just got to be careful you're not pushing through things you don't understand then just getting walked through the parts you get stuck on without fully taking it in
TerraReturns
TerraReturnsOP16mo ago
yea
Want results from more Discord servers?
Add your server