samedi 1 octobre 2022

C# - Random Name Generator from .txt-File [closed]

Iam trying to read Lists of Names of 3 different .txt-Files for a Name Generator. A few days ago I was still able to read a single Name of a single .txt-File. But things got out of hand and it looks like Forum-Threads and Youtube-Tutorials wont do the trick.

Would somebody kind be so nice and correct what I have broken and add some //-comments-for-complete-dummys, please?

using System;
using System.IO;
using System.Text;


public class VAInline
{
    public void main()
    {
   // random name generator (all races)
   
   // i dont understand this anymore
      Random rnd = new Random();
   
   // set path & textfile to string 
   // for easy handling & shorter lines
     string filePathNamesMale = @"D:\Tabletop\Setup\CharacterSheetGenerator\namesMale.txt";
     string filePathNamesFemale = @"D:\Tabletop\Setup\CharacterSheetGenerator\namesFemale.txt";
     string filePathNamesLast = @"D:\Tabletop\Setup\CharacterSheetGenerator\namesLast.txt";

   // read list of names from file to strings with []
   // for easy handling & shorter lines again
      string[] namesMale = File.ReadAllLines(filePathNamesMale);                    
      string[] namesFemale = File.ReadAllLines(filePathNamesFemale);                      
      string[] namesLast = File.ReadAllLines(filePathNamesLast);

   // i dont understand this anymore
      int maleIndex = rnd.Next(namesMale.Length);
      int femaleIndex = rnd.Next(namesFemale.Length);
      int lastIndex = rnd.Next(namesLast.Length);


   // write name to va text-variable 
      VA.SetText(namesOutput, namesMale[maleIndex] and namesFemale[femaleIndex] namesLast[lastIndex]);
   }
}



Aucun commentaire:

Enregistrer un commentaire