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

Posted: 20 Sep 2023 20:16
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.


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

Posted: 21 Sep 2023 00:12
by Jeff

Already solved, thanks


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

Posted: 21 Sep 2023 00:59
by BigBenEco

How did you solve it?


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

Posted: 21 Sep 2023 01:47
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"

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

Posted: 21 Sep 2023 01:51
by Jeff

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


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

Posted: 22 Sep 2023 13:43
by idaot

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