Example #1
0
    public static void Save()
    {
        // Get all IsPersistent board names
        string[] allBoardsContaining = BlackBoard.GetAllBoardsContaining("IsPersistent");

        // List of all objects to be saved. <string>board, <string>field, <string|int|float|bool>value
        List <object> list = new List <object>();

        for (int i = 0; i < allBoardsContaining.Length; i++)
        {
            string[] fields = BlackBoard.GetAllFieldsFromBoard(allBoardsContaining[i]);

            for (int j = 0; j < fields.Length; j++)
            {
                object value = BlackBoard.Read <object>(allBoardsContaining[i], fields[j]);

                list.Add(allBoardsContaining[i]);
                list.Add(fields[j]);

                if (value.GetType() == typeof(bool))
                {
                    list.Add("__BOOLEAN:" + ((bool)value == true ? "true" : "false"));
                }

                if (value.GetType() == typeof(int))
                {
                    list.Add("__INT32:" + value.ToString());
                }

                if (value.GetType() == typeof(string))
                {
                    list.Add(value);
                }
            }
        }

        BinarySaver.WriteBinFile(list.ToArray());
    }