[Solved] Struggling with Custom Input?

Posted: 27 Dec 2021 17:28
by justloveme94

Sorry to be a bother! I have gotten all my custom UI working except the custom input. I am currently trying to create a custom input for the Player to enter their name and last name. I have tried playing around with the PlayScript to hold the name string but I must not be placing it in the right spot or doing something wrong as it is not holding the variable and displays as blank space where the name should be.


Re: Struggling with Custom Input?

Posted: 28 Dec 2021 12:01
by idaot

Consider using Variable Triggers to display a custom variable value on a Custom UI: https://naninovel.com/guide/custom-vari ... e-triggers


Re: Struggling with Custom Input?

Posted: 29 Dec 2021 04:10
by justloveme94

So I tried adding the Custom Variable Trigger script to the Text field of the Input Field. I set the custom variable name as PlayerName (which has already been declared in resources). I set the On Variable Value Changed (string) both to the Input Field's Text and text.text. Unfortunately, nothing happens, PlayerName remains blank, nonexistent instead of the name I type in.


Re: Struggling with Custom Input?

Posted: 29 Dec 2021 12:18
by idaot

Make sure the variable value is registering properly via Variable Debug: https://naninovel.com/guide/custom-vari ... bles-debug Note that in order for it to register as a string, you need to wrap it in quotation marks. I suggest checking out the Custom UI example project for a working example of a Variable Trigger that triggers upon a string variable value change: https://naninovel.com/guide/user-interf ... omization


Re: Struggling with Custom Input?

Posted: 29 Dec 2021 15:17
by justloveme94

Okay, I checked out the Custom UI example. In the example script, the calendar string is changed via script. I tried setting, @set PlayerName="", within the script, attaching the Custom UI Trigger to the Input Field, but Debug is still not registering... I think my problem is that I'm still not understanding how to make the game register the custom input string in the input field by the Player and assigning it to the variable.


Re: Struggling with Custom Input?

Posted: 29 Dec 2021 16:42
by idaot

Are you using Naninovel's built-in VariableInputUI or your own? Because if you are making one from scratch then you'll have to program it too. If you don't have knowledge in C# then creating and modifying a VariableInputUI is the better option. I suggest starting from scratch with a fresh project, test the built-in VariableInputUI and make incremental changes from there. Be sure to follow the instructions given in the API reference: https://naninovel.com/api/#input


Re: Struggling with Custom Input?

Posted: 04 Jan 2022 17:30
by justloveme94

Hello again, I decided to take the coding route. The input field is correctly displaying the right name as the debug log is working. I read up on the custom variables for Naninovel, but the code does not seem to be working as intended for me as the variable is not registering under the debug for Naninovel.

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Naninovel;

public class CustomInput : MonoBehaviour
{
    private string PlayerFirstName;
    private string PlayerLastName;
    public GameObject inputFieldFirst;
    public GameObject inputFieldLast;

public void StoreFirstName()
{
    PlayerFirstName = inputFieldFirst.GetComponent<Text>().text;
    Debug.Log("Protag's Name is " + PlayerFirstName);
}

public void GetVariableValue(string PlayerFirstName)
{
    var variableManager = Engine.GetService<ICustomVariableManager>();
    var myValue = variableManager.GetVariableValue("PlayerFirstName");
    myValue = " ";
    variableManager.SetVariableValue("PlayerFirstName", myValue);
    Debug.Log("This is working properly.");
}

public void StoreLastName()
{
    PlayerLastName = inputLName;
    Debug.Log(PlayerLastName);
}
} 

Re: Struggling with Custom Input?

Posted: 10 Jan 2022 11:27
by idaot

I'm not sure what you're trying to achieve with the empty string value in myValue. Make sure you're not mixing private string PlayerFirstName with the Naninovel custom variable PlayerFirstName as you cannot use a Naninovel custom variable like a script variable. To access the Naninovel custom variable, you'll need to use GetVariableValue/SetVariableValue.


Re: Struggling with Custom Input?

Posted: 12 Jan 2022 02:34
by justloveme94

I was able to solve the coding issue I was having. For anyone else who would like to use the code. It successfully pulls the Player input for first and last name and assigns it to the proper custom variables via custom input menu.

Code: Select all

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Naninovel;

public class CustomInput : MonoBehaviour
{
    public string firstName;
    public string lastName;
    public GameObject inputFieldFirst;
    public GameObject inputFieldLast;

public void StoreFirstName()
{
    var variableManager = Engine.GetService<ICustomVariableManager>();
    var firstName = variableManager.GetVariableValue("PlayerFirstName");
    firstName = inputFieldFirst.GetComponent<Text>().text;
    Debug.Log("Protag's Name is " + firstName);
    firstName += " ";
    variableManager.SetVariableValue("PlayerFirstName", firstName);
}

public void StoreLastName()
{
    var variableManager = Engine.GetService<ICustomVariableManager>();
    var lastName = variableManager.GetVariableValue("PlayerLastName");
    lastName = inputFieldLast.GetComponent<Text>().text;
    Debug.Log("Protag's Name is " + lastName);
    lastName += " ";
    variableManager.SetVariableValue("PlayerLastName", lastName);
} 
}