Andrewgosu
The Silent Pandaren Helper
- Reaction score
- 716
Introduction: In this tutorial, I will cover the basics how to use game cache – how to store, retrieve and move information between maps.
Step 1 – Storing the information and moving it to another map
Lets get started by creating a map and naming it DemoMap. After that, open the variable editor (
) and create a game cache type variable. Name it Cache.
Now, you are ready for some information storing, but firstly, you need to initialize the game cache. Create an initialization trigger, and create the cache.
After the cache is initialized, lets move ahead to storing some information. The event and conditions don’t matter in this tutorial, so I will use the classic way, which is used in the Rexxar campaigans, also – a unit enters a region, store some information and load the new map.
After an event and some basic conditions have been created, you need to store the triggering unit and might as well the gold&lumber the owner of the unit has. (When storing data, each, eg, stored unit has to have an unique label, otherwise, the stored unit will overwrite the previous one.)
Note: Both maps - the one where you store and the other, where you restore - need the same instance of the unit you are storing. Otherwise, the game wont load the unit at all. (e.g. You have a modified hero called "Druglord", all the maps need the same instance of, where you are planning to store and restore it)
Do not forget to save the game cache after that!
Lastly, you need to load the new map. Note, the map has to be in a specified category in your computer and assumes you have the other map already created. In my case, the other maps name is DemoMap2 and it is located in the Warcraft III installation folder, under Maps\DemoMap2.w3x.
The complete trigger looks like this:
Step 2 – Retrieving the stored information
To retrieve the stored data to DemoMap2, you need to initialize the game cache again, from the DemoMap.
It is up to you, when you retrieve your information. I will restore it at map initialization.
To restore booleans, integers, reals or strings, you need to create corresponding types of variables to load the information to. We stored gold&lumber, so we need 2 integer variables. Create and name them respectively Gold and Lumber.
Tip: You do not need to create a variable for every value you want to store and restore later. You can use specified typed variable arrays.
As I said, you need to load the information to a variable. You need to use the exact same labels and categories, what you used to store the data.
Note: To reference the stored unit somehow, you need a unit variable. Create the variable, name it - Rexxar, in my case - and set the restored unit into a variable as "Last restored unit".
Because we saved the information to variables, the content of the game cache is not needed anymore, so we might as well clear and save it. (If you need the content later, skip this step)
Lastly, you just need to set the players gold and lumber to the values as they were in DemoMap originally.
The complete trigger looks like this:
Having followed these steps correctly, you should be able to store, move and restore data between two different maps.
Have fun and feedback is always appriciated.
Question: What is game cache?
A game cache is basically a memory area where you can store and, later,
restore previously stored data or information.
restore previously stored data or information.
Question: Can I switch between maps in multiplayer?
No, you cannot. You can use game cache in multiplayer to enchance spells or gameplay, but you cannot switch between maps. It is only for single player.
Step 1 – Storing the information and moving it to another map
Lets get started by creating a map and naming it DemoMap. After that, open the variable editor (
Now, you are ready for some information storing, but firstly, you need to initialize the game cache. Create an initialization trigger, and create the cache.
After the cache is initialized, lets move ahead to storing some information. The event and conditions don’t matter in this tutorial, so I will use the classic way, which is used in the Rexxar campaigans, also – a unit enters a region, store some information and load the new map.
After an event and some basic conditions have been created, you need to store the triggering unit and might as well the gold&lumber the owner of the unit has. (When storing data, each, eg, stored unit has to have an unique label, otherwise, the stored unit will overwrite the previous one.)
Note: Both maps - the one where you store and the other, where you restore - need the same instance of the unit you are storing. Otherwise, the game wont load the unit at all. (e.g. You have a modified hero called "Druglord", all the maps need the same instance of, where you are planning to store and restore it)
Do not forget to save the game cache after that!
Lastly, you need to load the new map. Note, the map has to be in a specified category in your computer and assumes you have the other map already created. In my case, the other maps name is DemoMap2 and it is located in the Warcraft III installation folder, under Maps\DemoMap2.w3x.
The complete trigger looks like this:
Step 2 – Retrieving the stored information
To retrieve the stored data to DemoMap2, you need to initialize the game cache again, from the DemoMap.
It is up to you, when you retrieve your information. I will restore it at map initialization.
To restore booleans, integers, reals or strings, you need to create corresponding types of variables to load the information to. We stored gold&lumber, so we need 2 integer variables. Create and name them respectively Gold and Lumber.
Tip: You do not need to create a variable for every value you want to store and restore later. You can use specified typed variable arrays.
As I said, you need to load the information to a variable. You need to use the exact same labels and categories, what you used to store the data.
Note: To reference the stored unit somehow, you need a unit variable. Create the variable, name it - Rexxar, in my case - and set the restored unit into a variable as "Last restored unit".
Because we saved the information to variables, the content of the game cache is not needed anymore, so we might as well clear and save it. (If you need the content later, skip this step)
Lastly, you just need to set the players gold and lumber to the values as they were in DemoMap originally.
The complete trigger looks like this:
Having followed these steps correctly, you should be able to store, move and restore data between two different maps.
Have fun and feedback is always appriciated.