About Global Variable

(xcygame) #1

Hello handsome administrator! There is no doubt that the type of the variable is rich, which can realize the more game function.
About global variables, my idea is simple: the variable every second in work, even if change the scenes.

I don’t know how much increase the difficulty of the global variable, but I’m sure this will bring Vinoma a brand-new game production experience. Please consider my suggestion, thank you!

(Leslie Young) #2

I am not sure what you are asking about. All Variables and Switches are global and available to all Vinoma Scenes.

(xcygame) #3

Hello handsome administrator ,thank you for your answer.my mother language is not English, expression is not clear,Please forgive me.

I know that all variables are global. I list the demonstration picture mean: It will automatically every second.
Another example:

Global Variable“A” set 1,we let it automatically +1 every second.After 10 seconds,Global Variable“A” is 10.

In short, variable will automatically “add”or"subtract"or“multiply”or"divide"every seconds
thank you!:grin::relaxed:

(Leslie Young) #4

You can try something like this.

Use the Vinoma Script Action to call StartCounter and StartCounter as needed.

In this case I have a variable called “counter” which will be incremented every second after StartCounter was called.

You can tweak this code do whatever need you have, like increment with higher value for example or change the timing from a second to something else.

using UnityEngine;
using VinomaEngine;
using plyCommon2;

public class MyFunctions : MonoBehaviour
	private const float timeout = 1.0f; // timer's interval (in seconds)
	private float timer = 0.0f;
	private int counter = 0;

	private void Update()
		// I check for > 0 to help determine when this should be running or not
		if (timer > 0.0)
			timer -= Time.deltaTime;
			if (timer <= 0.0f)
				timer = timeout; // so timer starts again
				counter = counter + 1;
				VinomaSceneController.Instance.PerformOperationOnVariable("counter", counter.ToString(), null, VinomaVarOperation.Set);

	public void StartCounter()
		timer = timeout; // start the timer
		counter = 0; // reset the value
		VinomaSceneController.Instance.PerformOperationOnVariable("counter", counter.ToString(), null, VinomaVarOperation.Set);

	public void StopCounter()
		timer = 0.0f; // set to 0 so timer stops runnung (see Update())

(xcygame) #5

Hello handsome administrator! Code looks very simple and friendly, but I encountered in the use of small problem: stay in 0 timer, and no increase in per second.
Would you please have a look at my Settings are incorrect:

Timer did not increase per second

I look forward to your guidance, thank you.

(Leslie Young) #6

The Text Action reads the value and sets the text (label). Then you wait forever at the Wait Action, which keeps looping on itself. There is nothing reading any new value from the counter and updating the text/label with that value and that is why you do not see the value changing.

You could add a Goto Action to jump above the Text Action so it can read the new value and update the text/label but you obviously would not want that since your Vinoma Scenes would then not be able to continue.

Enter, UI Updaters. http://www.plyoung.com/vinoma-ui-updaters.html

(xcygame) #7

Ok, I see. Thank you very much!:grin::blush: