Tutorial - Global storage – Ylands

From Bohemia Interactive Community
Jump to navigation Jump to search

Global Storage is a type of Game Logic. Its strength is that whatever variable, array or Custom Instruction you declare in GS script, it becomes accessible from within every other script attached to any object. If you have some programming background, you can think of them as something similar to static variables.


When you create a new GS object in your scene (you can have as many as you like), you will be able to work with its variables, arrays and Custom Instructions by opening it in the left side menu under Variables and Local Instructions.


In general, GS are best used to store “global” game information, gameplay scripts, local player references and similar.


The Spawn Point

When you look at the Spawn Point Game Logic in the scene, you’ll see that in its script we store the Player who has spawned there into a Player variable, which is declared in Global Storage 1 object. This is a good practice because many times you need to have your local Player stored - many instructions require you to provide which player they should affect (for which Player should an UI be shown etc.).


The Time Trigger

Here we simply write out the Player (their name) that has spawned in this scene ten seconds ago.


The Button

When you press the button the game will tell you how many times you have entered the Trigger Zone located in front of it. This is possible because the count is stored in the Global Storage - if the number of entries were stored only in Trigger Zone’s script, there would be no way for the Button’s script to access it and read it.