I have a question about Custom Functions.

Posted: 23 Dec 2022 09:02
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?


Re: I have a question about Custom Functions.

Posted: 23 Dec 2022 09:10
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


Re: I have a question about Custom Functions.

Posted: 26 Dec 2022 06:41
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#?


Re: I have a question about Custom Functions.

Posted: 26 Dec 2022 09:39
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.