Tutorial - Global storage – Ylands

From Bohemia Interactive Community
Jump to navigation Jump to search
(Created page with " ---- {{Ylands editor navbox}} {{DEFAULTSORT:{{#sub:{{PAGENAME}}|18}}}} Category: Tutorial")
 
No edit summary
Line 1: Line 1:
'''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.


----
----

Revision as of 15:21, 28 May 2020

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.



Template:Ylands editor navbox