A Simple log print command

Share custom commands, script functions, actor implementations and other Naninovel plug-ins you've created.
Post Reply
LinkStar
Posts: 1
Joined: 25 Jun 2022 22:10

A Simple log print command

Post by LinkStar »

I couldn't find a way to print the log to console directly from Naniscript, so I created it.
You can select the type of log to output and use it with a script expression to increase its utilization.

Code: Select all

using Naninovel;
using Naninovel.Commands;
using UnityEngine;

/// <summary>
/// print Logs provided text
/// </summary>
[CommandAlias("printLog")]
public class PrintLogCommand : Command
{
    /// <summary>
    /// Content for logging
    /// </summary>
    [RequiredParameter, NamelessParameterAlias]
    public StringParameter content;
    /// <summary>
    /// log type
    /// 0: log 1:logWarning, 2:LogError, 3: throw new exception and stop playing
    /// </summary>
    [ParameterAlias("type")]
    public IntengerParameter logType;
    public override UniTask ExecuteAsync (AsyncToken asyncToken = default)
    {
        if(Assigned(logType))
        {
            if (!TypeValueIsInRange()) throw new Exception(nameof(logType), $"Provided logType {logType} is out of range!");
            switch(logType)
            {
                case 0: Debug.Log(content); break;
                case 1: Debug.LogWarning(content); break;
                case 2: Debug.LogError(content); break;
                case 3: throw new System.NotImplementedException(content); break;
            }
        }
        else Debug.Log(content);
        return UniTask.CompletedTask;
    }
    protected virtual bool TypeValueIsInRange() => (logType <= 3 || logType >= 0) ? true : false;
}

How to use (example)

Code: Select all

;Logs a simple "Hello World" text
@printLog "Hello World"

;gives random demage, if player's HP is lower than 0, throws Exception
@set HP=8
@set attackPower=Random(1, 20)
@set deffencePower=1
hades:Take my sword! YEEEE HYAA!!!!
@set HP=deffencePower-attackPower

@if HP < 0
    @printLog "Error!! Player Hp is lower than 0!" type:3
@endif
Post Reply