BoettcherDasOriginal / LeoConsole

LeoConsole is a terminal with many features! It allows you to quickly and easily program smaller or larger console functions or use those of others. It is written in C# 10 under .NET 6
GNU General Public License v3.0
2 stars 0 forks source link

[Bug] Cannot use console data in PluginMain #12

Closed alexcoder04 closed 2 years ago

alexcoder04 commented 2 years ago

Maybe I am doing something wrong, but it seems to me that the data values are not set yet, when PluginMain() runs. Is there a way to fix it?

my code:

public void PluginMain()
{
  _data = new ConsoleData();
  Console.WriteLine(_data.SavePath); // is null
  // ...
}
alexcoder04 commented 2 years ago

Here is my code:

 public void PluginMain(){
  _data = new ConsoleData();

  _Commands = new List<ICommand>();
  _Commands.Add(new Script());
  _Commands.Add(new ListScripts());
  _Commands.Add(new Exec());

  Console.WriteLine("savepath: " + _data.SavePath + ".");
  Console.WriteLine("savepath: " + data.SavePath + ".");
}

And here is the output:

Startet...
Keine Updates Gefunden!
Lädt: Users.lcs
Users.lcs erfolgreich geladen
Lädt: Plugins
savepath: . # <- nothing here
savepath: . # <- nothing here
Erfolgreich 5 Plugins geladen!
Registriere: Datas
Erfolgreich 6 Datas registriert!
Registriere: Commands
Erfolgreich 30 Commands registriert!

--- LeoConsole v1.5.0 ---
BoettcherDasOriginal commented 2 years ago

Here is my code:

 public void PluginMain(){
  _data = new ConsoleData();

  _Commands = new List<ICommand>();
  _Commands.Add(new Script());
  _Commands.Add(new ListScripts());
  _Commands.Add(new Exec());

  Console.WriteLine("savepath: " + _data.SavePath + ".");
  Console.WriteLine("savepath: " + data.SavePath + ".");
}

And here is the output:

Startet...
Keine Updates Gefunden!
Lädt: Users.lcs
Users.lcs erfolgreich geladen
Lädt: Plugins
savepath: . # <- nothing here
savepath: . # <- nothing here
Erfolgreich 5 Plugins geladen!
Registriere: Datas
Erfolgreich 6 Datas registriert!
Registriere: Commands
Erfolgreich 30 Commands registriert!

--- LeoConsole v1.5.0 ---

I found the mistake. You can not use _data.SavePath in PluginMain(), because data will be registered after PluginMain() is called.

BoettcherDasOriginal commented 2 years ago

I tried to fix it, but due to the register mechanic, it is impossible to fix it. Why do you want to use it in PluginMain()? @alexcoder04

alexcoder04 commented 2 years ago

I tried to fix it, but due to the register mechanic, it is impossible to fix it. Why do you want to use it in PluginMain()? @alexcoder04

I want to check the SavePath location and create the scripts folder inside.

What about renaming PluginMain() to something like PluginInit() and adding another PluginMain() function, which is called after data is registered?

BoettcherDasOriginal commented 2 years ago

I tried to fix it, but due to the register mechanic, it is impossible to fix it. Why do you want to use it in PluginMain()? @alexcoder04

I want to check the SavePath location and create the scripts folder inside.

What about renaming PluginMain() to something like PluginInit() and adding another PluginMain() function, which is called after data is registered?

yeah, this might could be a solution, I think I will do it like this