Search Unity

Resolved Handle Bolt Variables with C# script

Discussion in 'Visual Scripting' started by SPNK78, Apr 7, 2021.

  1. SPNK78

    SPNK78

    Joined:
    Mar 8, 2021
    Posts:
    13
    Hello,

    I want to update my Bolt variables with a C# script (https://docs.unity3d.com/bolt/1.4/manual/bolt-variables-api.html)

    I tried this simple script to update a Scene Variable :


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Photon.Pun;
    5. using Bolt;
    6. using Ludiq;
    7.  
    8.  
    9. public class ModifyVariable : MonoBehaviour
    10. {
    11.  
    12.     void Start()
    13.     {
    14.  
    15.         Variables.Scene.Set("Health", 100);
    16.  
    17.      }
    18. }
    But get the compilation error :
    Assets\VariableBolt.cs(15,19): error CS0119: 'Variables.Scene(Scene?)' is a method, which is not valid in the given context


    What did I miss to make this work?

    Thanks
     
  2. SPNK78

    SPNK78

    Joined:
    Mar 8, 2021
    Posts:
    13
    Hello,

    I finally succeded by myself, here is whjat it works for me if someone need :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. //using Photon.Pun;
    5. using Bolt;
    6. //using Ludiq;
    7.  
    8.  
    9.  
    10. public class VariableBolt : MonoBehaviour
    11. {
    12.  
    13.     // Object init if need to handle Object Variable
    14.     private GameObject exampleOne;
    15.     private void Start()
    16.     {
    17.  
    18.         /*Handle Scene Variables - both works */
    19.  
    20.         //Variables.ActiveScene.Set("Health", 100);
    21.         // Variables.Scene(gameObject).Set("Health", 100);
    22.  
    23.         /*Handle Object variables*/
    24.         exampleOne = GameObject.Find("ObjectName");
    25.         Variables.Object(exampleOne).Set("Health", 100);
    26.     }
    27. }
     
    Mr_Htet, domportera, OG1337OG and 5 others like this.
  3. ddplay

    ddplay

    Joined:
    May 14, 2019
    Posts:
    3
    cool man
     
  4. unity_SQMFZUX0l5QpBA

    unity_SQMFZUX0l5QpBA

    Joined:
    May 20, 2022
    Posts:
    10
    Hello ! :D

    i up for .... how to GET ?
    y try
    Code (CSharp):
    1.  
    2.         exampleOne = GameObject.Find("SaveData");
    3.         int health = (int)Variables.Object(exampleOne).Get("health");
    4.  
    how to put result in variable ?
    example :
    SaveHealth = result of int health = (int)Variables.Object(exampleOne).Get("health");

    can you help me ? :)
     
    Last edited: Dec 27, 2022