TIM.Console
  • Quick start
  • User Interface
  • Log
  • Commands
    • PartType C#
    • CmdFormula C#
    • CmdInputResult C#
  • Support
Powered by GitBook
On this page
  • Logchain
  • Example
  • Hidden messages

Log

How to do logs in Console

PreviousUser InterfaceNextCommands

Last updated 1 year ago

You still can call Debug.Log() or print()

Also you can use TIM.Console.Log()

Here is an example:

TIM.Console.Log("Game started");

Also you can change the MessageType of your message:

Message types:

💬 Default

🟨 Warning

🟥 Error

🟦 Network

TIM.Console.Log("Server started", MessageType.Network);

Logchain

Sometimes an in-game event does not happen immediately, it can be divided into several stages. 'Logchain' was created for this purpose

Example

You are downloading an image from Internet in 3 stages:

  1. Web request

  2. Downloading

  3. Converting downloaded data to Texture2D

You can group all these messages into one Logchain. Just give it name.

For example: "Image downloading". Here is how you can print a message:

Console.Log("Your log", MessageType.Default, "Image downloading");

So how our method can look like:

IEnumerator DownloadImage(string imageUrl)
    {
        WWW www = new WWW(imageUrl);
        string logchain = "Image downloading";

        Console.Log("Web request sent", MessageType.Network, logchain);
        yield return www;
        
        if (www.error != null)
        {
            Console.Log(www.error, MessageType.Error, logchain);
        }
        else
        {
            Console.Log("data has been downloaded", MessageType.Network, logchain);
            Texture2D texture = www.texture;
            
            if (texture == null)
            {
                Console.Log("Data doesn't contant a texture!", MessageType.Error, logchain);
            }
            else
            {
                Console.Log("Success!", MessageType.Default, logchain);
            }
        }
    }

Lets try it!

Execute our coroutine by StartCoroutine() method. And paste image URL as argument.

private void Start()
{
    // I found random image from internet and copied the URL:
    StartCoroutine(DownloadImage("https://www.sunhome.ru/i/wallpapers/221/frukti-oboi.orig.jpg"));
}

Open console by ` and you can see that messages are displayed in Console window and in Logchain window as well

Hidden messages

Hidden messages are hidden in Console (but not hidden in Logchain window)

Lets take our last example with downloading image. If we will download images many times we will have many messages in Console. But we can organize it better! We can hide logs in Console but keep them visible in Logchain window. You just need to set last argument hidden of TIM.Console.Log() function to true:

Console.Log("Web request sent", MessageType.Network, "Logchain name", true);

And how our function looks like now:

IEnumerator DownloadImage(string imageUrl)
    {
        WWW www = new WWW(imageUrl);
        string logchain = "Image downloading";

        Console.Log("Web request sent", MessageType.Network, logchain, true);
        yield return www;
        
        if (www.error != null)
        {
            Console.Log(www.error, MessageType.Error, logchain); // we don't want to hide errors
        }
        else
        {
            Console.Log("data has been downloaded", MessageType.Network, logchain, true);
            Texture2D texture = www.texture;
            
            if (texture == null)
            {
                Console.Log("Data doesn't contant a texture!", MessageType.Error, logchain); // we don't want to hide errors
            }
            else
            {
                Console.Log("Success!", MessageType.Default, logchain, true);
            }
        }
    }

What we will see in Console:

You can enable visibility of hidden messages by clicking this button:

Toggle it and what you can see now:

How it looks like in Console
How it looks like in Console
How it looks like in console
Console is clear. But Logchain exists.