0
Answered

how to get ValueInput of list<string> type by code

王坤缺德 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 3

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Ludiq;
using Bolt;
using System.Linq;
using System;

public class WdkUnit : Unit
{
    private List<ControlOutput> OptionsOutputList = new List<ControlOutput>();

    [UnitHeaderInspectable("ChatOptionsList")]
    public List<string> ChatOptionsList = new List<string>();

    public ValueInput ChatOptionsListInput;

    protected override void Definition()
    {
        
        foreach (var item in ChatOptionsList)
        {
            Debug.Log("ChatOptionsList Add item");
            var c = ControlOutput(item);
            OptionsOutputList.Add(c);
        }

        ChatOptionsListInput = ValueInput<List<string>>("ChatOptionsListInput", ChatOptionsList);
        ChatOptionsListInput.GetValue<List<string>>();
    }
}


when I use ChatOptionsListInput.GetValue<List<string>>(),I got the MissingValuePortInputException.

tall me how to get the ChatOptionsListInput value please,or give me some link to learn about coding with Bolt.


Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

A couple red flags:

- You can't GetValue in definition. You should be using that in the output value method, or within a control inputs invoked method. Or you will get an error. 

- You also can't Serialize ports, so add [DoNotSerialize] over any port variable declaration. 

- And last but not least, if you want your list to carry over between serialization, so when it enters play mode, or after a hot reload, Mark it with [Serialize]. That should take care of everything.

If you need further explanation about why with any of this, let me know.

Thank you for your help

what I want to do is make ControlOutput dynamic in edit mode.this is recomposed:

public class WdkUnit : Unit
{
    [DoNotSerialize]
    public ControlInput theControlInput;

    [DoNotSerialize]
    private List<ControlOutput> OptionsOutputList = new List<ControlOutput>();

    [Serialize]
    [UnitHeaderInspectable("Options")]
    public List<string> ChatOptionsList = new List<string>();

    [DoNotSerialize]
    public ValueInput ChatOptionsListInput;

    protected override void Definition()
    {
        theControlInput = ControlInput("ci", f =>
        {
            //Debug.Log("theControlInput");
            foreach (var item in ChatOptionsListInput.GetValue<List<string>>())
            {
                Debug.Log(item);
            } 
        });

        foreach (var item in ChatOptionsList)
        {
            //Debug.Log("ChatOptionsList Add item");
            var c = ControlOutput(item);
            OptionsOutputList.Add(c);
        }

        ChatOptionsListInput = ValueInput<List<string>>("ChatOptionsListInput", ChatOptionsList);
        //ChatOptionsListInput.GetValue<List<string>>();
    }
}


I can use ChatOptionsList property to do that,but how to do that with the last list unit(ChatOptionsListInput)?

So does that means I cant only use GetValue in running mode? and only use property to make dynamic ControlOutput in edit mode?

Answered

Hi! Yes, GetValue can only be called at runtime. Your graph is not traversed while in edit mode.

This is why "settings" like that ChatOptionsList property were created. It makes sense if you think about it: they define language-level constructs that change how your logic fits together.