Search Unity

Accessing Bolt variables through C# with additions

Discussion in 'Visual Scripting' started by WillyG99, Sep 3, 2022.

  1. WillyG99

    WillyG99

    Joined:
    Jul 3, 2016
    Posts:
    4
    Hi!

    I have a simple line of code that i can't seem to figure out why it won't work.

    1. Variables.Saved.Set("curRad", - amount);

    I wanna subtract my "curRad" saved variable from bolt with my int(amount).
    But this logic currently just sets my curRad to whatever number my (amount) is.


    I have tried so many other things aswell but i can't seem to figure this out, a little pointer would be helpful.
     
  2. WillyG99

    WillyG99

    Joined:
    Jul 3, 2016
    Posts:
    4
    I'll need something more similiar to this i guess:
    Variables.Saved.Set
    ("curRad" = "curRad" -amount);

    Any help would be appreciated
     
  3. POOKSHANK

    POOKSHANK

    Joined:
    Feb 8, 2022
    Posts:
    299
    you would need something along the lines of

    Code (CSharp):
    1.      
    2.  
    3.  curRad = (int)Variables.Object(gameObject).Get("BOLT_curRad");
    4.  Variables.Saved.Set("BOLT_curRad", curRad - 1);
    5.  
    6.  
    with a pre declared integer that you can change freely.
    make sure you set you get the variable from unity before trying to use it.
     
    WillyG99 likes this.
  4. WillyG99

    WillyG99

    Joined:
    Jul 3, 2016
    Posts:
    4
    It worked thank you!
     
    POOKSHANK likes this.