-4

So I'm making a game in a C# Console Application and I am curious on how to do something like a animated text style like you see in RPG's for example. Any help would be appreciated.

1 Answers1

1

This function should do the trick:

static void SimulateTyping(string message, int delay = 100) {        //'delay' is optional when calling the function
    foreach (char character in message)                               //take every character from your string seperately
    {
        Console.Write(character);                                     //print one character
        System.Threading.Thread.Sleep(delay);                         //wait for a small amount of time
    }
}

You can also make it generic, to write more than just strings (int, float etc.):

static void SimulateTyping<T>(T message, int delay = 100) {
    foreach (char character in message.ToString())
    {
        Console.Write(character);
        System.Threading.Thread.Sleep(delay);
    }
}
CookedCthulhu
  • 744
  • 5
  • 14
  • It's showing me an error: error CS5001. – Harry Court Oct 21 '16 at 10:52
  • It's showing me an error; Error CS5001 – Harry Court Oct 21 '16 at 10:53
  • `using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace C_sharp_Testing { class Program { static void Main(string[] args) { } static void SimulateTyping(T message, int delay = 100) { foreach (char character in message.ToString()) { Console.Write(character); System.Threading.Thread.Sleep(delay); } } } } ` – Harry Court Oct 21 '16 at 10:54
  • I copied your code into VS and it works without errors. Try to rebuild your solution or copy it into a new project. – CookedCthulhu Oct 21 '16 at 12:25