0
Answered

how do I get a variable from another script and store it in Game Creator?

eagleeyez 2 months ago in Game Creator updated by Marti (Lead Developer) 2 months ago 1

Well the title says it all

how do I get a variable from another script and store it in Game Creator?

Unity version:
2018.4.12f
Game Creator version:
1.0.6

Answer

Answer
Answered

I don't have all the necessary information, so I'll make an educated guess and imagine you're making a custom Action that stores the "integer" value into a Local Variable.

To do so, you'll need first a reference to the component that contains the value. For example, let's say it's called MyComponent and the value is "myValue.

public MyComponent myComponent;


To access the value of MyComponent reference you can use:


int value = this.myComponent.myValue;


To store the value into a Global Variable, you use the VariablesManager. These are explained in detail at our documentation page.


VariablesManager.SetGlobal("my-global-variable-name", value);
Answer
Answered

I don't have all the necessary information, so I'll make an educated guess and imagine you're making a custom Action that stores the "integer" value into a Local Variable.

To do so, you'll need first a reference to the component that contains the value. For example, let's say it's called MyComponent and the value is "myValue.

public MyComponent myComponent;


To access the value of MyComponent reference you can use:


int value = this.myComponent.myValue;


To store the value into a Global Variable, you use the VariablesManager. These are explained in detail at our documentation page.


VariablesManager.SetGlobal("my-global-variable-name", value);