So I have a class file. Inside the class is a void which is started in the Program.cs. I used 'LavaSurvival.Init("properties/lava.properties")' in the Program.cs. I'm only pretty new to coding, so it's probably something I didn't know XD. The problem is that I continue to get this error:
Type: IndexOutOfRangeException
Source: Test
Message: Index was outside the bounds of the array.
Target: Init
Trace: at Test.LavaSurvival.Init(String path) in C:\mypath=3\LavaSurvival.cs:line 61
Heres the code for the void:
public static void Init(string path)
{
if (File.Exists(path))
{
string[] lines = File.ReadAllLines(path);
foreach (string line in lines)
{
if (line[0] != '!' && line != "" || line[0] != '#')
{
string key = line.Split('=')[0].Trim();
string value = line.Split('=')[1].Trim();
switch (key.ToLower())
{
case "lava-mode":
try
{
if (value != "normal" && value != "rising")
{
Server.s.Log("Invalid lava mode. Using default.");
}
else
{
lavamode = value;
}
}
catch { }
break;
case "lava-speed":
try
{
bool failed = false;
try
{
int.Parse(value);
}
catch { Server.s.Log("Invalid lava-speed. Using default"); failed = true; }
if (!failed)
{
if (int.Parse(value) > 20)
{
Server.s.Log("Lava-Speed cannot excede 20. Using default.");
}
else if (int.Parse(value) < 1)
{
Server.s.Log("Lava-Speed cannot be less than 1. Using default.");
}
else
{
lavaspeed = int.Parse(value);
}
}
}
catch { Server.s.Log("An Error Occurred loading the lava-speed!"); }
break;
case "time-before-lava":
try
{
bool failed = false;
try
{
int.Parse(value);
}
catch { Server.s.Log("Invalid time before lava. Using default."); failed = true; }
if (!failed)
{
if (int.Parse(value) > 60)
{
Server.s.Log("The time-before-lava cannot excede 60 minutes. Using default.");
}
else if (int.Parse(value) < 1)
{
Server.s.Log("The time-before-lava cannot be less than 1 minute. Using default.");
}
else
{
minutesbefore = int.Parse(value);
}
}
}
catch { Server.s.Log("An Error Occurred loading the time-before-lava!"); }
break;
case "time-after-lava":
try
{
bool failed = false;
try
{
int.Parse(value);
}
catch { Server.s.Log("Invalid time after lava. Using default."); failed = true; }
if (!failed)
{
if (int.Parse(value) > 60)
{
Server.s.Log("The time-after-lava cannot excede 60 minutes. Using default.");
}
else if (int.Parse(value) < 1)
{
Server.s.Log("The time-after-lava cannot be less than 1 minute. Using default.");
}
else
{
minutesafter = int.Parse(value);
}
}
}
catch { Server.s.Log("An Error Occurred loading the time-after-lava!"); }
break;
}
}
else if (line[0] == '!')
{
bool failed = false;
try
{
string name = line.Split(' ')[0];
string x1 = line.Split(' ')[1];
string x2 = line.Split(' ')[2];
string x3 = line.Split(' ')[3];
if (!File.Exists("levels/" + line.Split(' ')[0].ToLower() + ".lvl"))
{
Server.s.Log("Failed to load the lavamap, " + name.ToLower() + " because the map does not exist in levels/");
failed = true;
}
else
{
ushort.Parse(x1);
ushort.Parse(x2);
ushort.Parse(x3);
}
if (!failed)
{
LavaSurvivalMaps.Add(name, ushort.Parse(x1), ushort.Parse(x2), ushort.Parse(x3));
}
failed = false;
}
catch { Server.s.Log("One of your settings for the map, " + line.Split(' ')[0] + " was invalid!"); failed = false; }
}
}
}
}
Thanks in advance, if you can help me fix this error :D