I wrote my program with many global variables and only with public void methods. So I want to change my methods to private static methods with return values. That's what I've done.
Now my program will only pass once through "globalChatMessageReceived" of TwitchLib and then it does nothing at all. No problems or errors will display and the program is running correctly and saves data but it will only doing this once.
I am using
FindPokemonName(MessageSplitForPokemonName[1]);
without return values and
(string[] PokedexName, Boolean ChosenPokemonIsAvailable, Boolean ChosenPokemonIsNoStarter, string NameOfChosenPokemon) = FindPokemonName(MessageSplitForPokemonName[1]);
with return values.
Here is the code with global variables and no return values:
public void FindTrainerID(string TrainerID, string ChatDisplayName)
{
TrainerVorhanden = false;
if (File.Exists(@"C:\txt\trainer\" + TrainerID + ".txt"))
{
string FoundTrainer = File.ReadAllText(@"C:\txt\trainer\" + TrainerID + ".txt");
Trainer = FoundTrainer.Split('\\');
TrainerVorhanden = true;
}
}
And that's what I've done now with return values:
private static (string[] Trainer, bool TrainerAvailable) FindTrainerID(string TrainerID)
{
string[] Trainer = new string[5];
Boolean TrainerAvailable = false;
if (File.Exists(@"C:\txt\trainer\" + TrainerID + ".txt"))
{
string FoundTrainer = File.ReadAllText(@"C:\txt\trainer\" + TrainerID + ".txt");
Trainer = FoundTrainer.Split('\\');
TrainerAvailable = true;
}
return (Trainer, TrainerAvailable);
}
I tried the program without using the methods with a return value. The program is running constantly with the TwitchLib method "globalChatMessageReceived".
If I'm using return values it does nothing after that.
You might find it easier to work with a class rather than returning a tuple like this.
For instance, declare this data class:
And then give this a try:
Also food for thought: Does
Trainer
absolutely have to be an array, or could you use a more dynamic collection type (such asList<string>
)?