Forum rules - please read before posting.

Changing global variables through C# script.

I'm having very inconsistent results trying to change global variables through a C# script. Earlier I was able to change the health value of an enemy through trial and error, eventually ending up with this set of code.

using AC

{
    public GVar healthRecord;

    healthRecord.FloatValue = enemy.health;
        AC.GlobalVariables.SetFloatValue(9, healthRecord.FloatValue);
}

This method works. But when I tried it with a boolean variable at a later time, it does not change.

using AC

{
    public GVar wonCellarPuzzle;

    wonCellarPuzzle.BooleanValue=true;
            AC.GlobalVariables.SetBooleanValue(22, wonCellarPuzzle.BooleanValue);
}

From what I understand I should just be able to write

AC.GlobalVariables.SetBooleanValue(22, true);

But that does not work either. Really confused as to how this system works.

Comments

  • You don't need to create a GVar class of your own - you can assign the values directly, i.e.:

    AC.GlobalVariables.SetFloatValue(9, enemy.health);
    AC.GlobalVariables.SetBooleanValue(22, true);
    

    If these aren't working, check that the types match - i.e. the variable with an ID of "22" is a Boolean.

    It's also possible to refer to variables by name. Try this for the latter instead, replacing "WonCellarPuzzle" with the name of your Global Variable:

    GVar myVariable = GlobalVariables.GetVariable ("WonCellarPuzzle");
    myVariable.BooleanValue = true;
    

    Does that work?

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.