I have a question about Custom Functions.

Discuss authoring naninovel scenario scripts.
Post Reply
booksuny
Posts: 47
Joined: 26 Sep 2022 12:37

I have a question about Custom Functions.

Post by booksuny »

Code: Select all

[Naninovel.ExpressionFunctions]
public static class itemGET
{

public static itemBuffer _itemBuffer;


public static void itemDel(string name)
{
    foreach (var i in _itemBuffer.items)
    {
        if (name == i.name)
        {

            i.get = false;
            Debug.Log(i.get);
        }
    } 
    
}

public static void itemGet(string name)
{
    foreach (var i in _itemBuffer.items)
    {
        if (name == i.name)
        {
            i.get = true;
            Debug.Log(i.get);
        }
    } 
}
}

I wrote the same code as above.

I want to use itemGet/itemDel within NaniNobel.

Code: Select all

@itemGet itemname

I tried to use it like this, but it doesn't work.

How do I use Custom Functions in naninovell?

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

Re: I have a question about Custom Functions.

Post by idaot »

You are confusing functions with commands. Functions can be injected into script text while commands are identified by the @ at the beginning.

Functions also need to return a alphanumerical value, whereas commands don't. However, commands need an ExecuteAsync function to work. You can find a template here: https://naninovel.com/guide/custom-commands.html

booksuny
Posts: 47
Joined: 26 Sep 2022 12:37

Re: I have a question about Custom Functions.

Post by booksuny »

idaot wrote: 23 Dec 2022 09:10

You are confusing functions with commands. Functions can be injected into script text while commands are identified by the @ at the beginning.

Functions also need to return a alphanumerical value, whereas commands don't. However, commands need an ExecuteAsync function to work. You can find a template here: https://naninovel.com/guide/custom-commands.html

Thank you for your reply.

I'm writing the material because there are still some confusing parts.

I want to execute the itemGet function I wrote within Nani Nobel, does it mean that there is no way to execute the code I wrote?

What code should I refer to to to execute that function, as is commonly used in C#?

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

Re: I have a question about Custom Functions.

Post by idaot »

You'll need to turn it into a command. Commands can be set up in many ways and can include other functions as long as it is routed to ExecuteAsync, you can find many examples in the Command folder in Naninovel.

Post Reply