How to create a Custom Command that can block Naninovel's text reading?

Using Naninovel C# APIs: adding custom actor implementations or commands, overriding engine services, integrating with other systems, etc.
Post Reply
Jeff
Posts: 4
Joined: 20 Sep 2023 19:17

How to create a Custom Command that can block Naninovel's text reading?

Post by Jeff »

Hello, I've basically created a Custom Command called "doMoveAnimation" that moves a character based on a provided sequence. I have a parameter called "pause" that indicates that the next Naninovel lines can only be read after the movement has been completed.

Code: Select all

@doMoveAnimation ids:"101" sequence:"LD | W1 | M2"
@doMoveAnimation ids:"102" sequence:"LL | W2 | M4" pause:true
@doMoveAnimation ids:"103" sequence:"LR | W1"
@doMoveAnimation ids:"104" sequence:"LD | W1 | M2"

In the case above, I would execute the first two lines and then wait for the characters to finish their movement before reading the lines with IDs 103 and 104. Can you help me with any ideas on how to solve this issue?

Thanks.

Jeff
Posts: 4
Joined: 20 Sep 2023 19:17

Re: How to create a Custom Command that can block Naninovel's text reading?

Post by Jeff »

Already solved, thanks

BigBenEco
Posts: 7
Joined: 24 Apr 2023 04:18

Re: How to create a Custom Command that can block Naninovel's text reading?

Post by BigBenEco »

How did you solve it?

Jeff
Posts: 4
Joined: 20 Sep 2023 19:17

Re: How to create a Custom Command that can block Naninovel's text reading?

Post by Jeff »

BigBenEco wrote: 21 Sep 2023 00:59

How did you solve it?

Code: Select all

[CommandAlias("doMoveAnimation")]
public class TreatingInputMove : Command
{
     //...
     //Other Parameters...
     //...

    public BooleanParameter Pause; // Control whether to pause or not

    //UniTaskCompletionSource to handle asynchronous task completion
    private readonly UniTaskCompletionSource<object> completionSource = new UniTaskCompletionSource<object>();

	public override async UniTask ExecuteAsync(AsyncToken asyncToken = default)
    {
        //...
        //Some code That will call other Scripts...
        //...

        
        if(Assigned(Pause) && Pause)//Checking if the Pause is assigned and if is true
        {    
            CommandsQueue.OnEndCommand += CommandCompleted;//Attaching CommandCompleted to the OnEndCommand event
            await completionSource.Task; //Waiting for the task to completion
        }
        else // If Pause is not assigned or if Pause is false, we complete the task immediately
            await UniTask.CompletedTask;
    }

   //When OnEndCommand is triggered we inform that we can continue with the naninovel script...
    public void CommandCompleted()
    {
        completionSource.TrySetResult(null); //task is completed
    }
    
}

Example Naninovel Script:

Code: Select all

@doMoveAnimation ids:"100,101,102" sequence:"LD | W1 | M2 | TT | LL | W1 | M4 | LU"
@doMoveAnimation ids:"101" sequence:"LD | W1 | M2 | TT | LL | W1 | M4 | LU" pause:true
@doMoveAnimation ids:"100" sequence:"LR | W1 | M2 | TT | LL | W1 | M4 | LU"
Jeff
Posts: 4
Joined: 20 Sep 2023 19:17

Re: How to create a Custom Command that can block Naninovel's text reading?

Post by Jeff »

Basically, I created an event to inform that an asynchronous task should be completed, and then Naninovel script can continue

idaot
support
Posts: 260
Joined: 01 Aug 2020 08:25

Re: How to create a Custom Command that can block Naninovel's text reading?

Post by idaot »

You can also use UniTask.Delay, UniTask.WaitUntil or await a tweener to completion.

Post Reply