Tutorial Game Cache

jonadrian619

-___-
Reaction score
240
Game Cache Tutorial

Tutorial by jonadrian619

Note: Although information about the Game Cache is shown in the Campaign Basics section, more useful information and support about Game Caches are shown and displayed here.

Table of Contents:
1) Operating Game Caches
2) Game Cache Actions
3) Saving heroes using Game Caches
4) Advanced Game Cache Techniques

FAQ about Game Caches
1) What is a Game Cache?
A cache is a file created from a map that is saved on your computer thats stores information. The game cache can store information from one level, and load it when you play the next level. It can save objects like a hero, Integer value, Real value or character, and load them again after the level is finished.
2) What is the purpose in creating Game Caches?
The purpose is usual, to save objects or values in a particular level, and load these objects, values again in the next or higher levels. There are other advanced purposes in creating one. They will be discussed later.

Operating Game Caches:
Now, here's where we are standing. Before you create a Game Cache, you should create a Variable first. Go to Variables (With the X icon in it, or hotkey Ctrl+B). Click New Variable and then type the name of your variable. Then set it's type to 'Game Cache'. If you have multiple game caches, check the 'Array' checkbox and set the size (If you have multiple game caches) Then click OK.
Now you have a Game Cache variable which can be used to associate game caches.


Game Cache Actions
Here are the actions of the Game Cache category which are shown in the trigger editor. To create a Game Cache action, click the New Action (Hotkey Ctrl+R) button and click a 'Game Cache - ' Action. Each action has useful details and examples.


Game Cache - Create Game Cache
- Creates a new Game Cache from a map. The Game Cache should be created from your map. Type the map filename in the 'MapName.w3v' field value and change it to your map's filename. The game cache should be from your map so that it's functions will work properly. If the map filename you have typed does not exist, the cache will be created.

Game Cache - Save Game Cache
- Saves the game cache, using the same filename from which it was created. If you use the Actions; Store Integer,Boolean, Unit, etc., then using the Save Game Cache action will save those objects and are available for restoration.

Game Cache - Store Unit
- Stores unit as a Label in a Category in an existing Game Cache. 2 ways to select a unit. First select a function like last created unit, picked unit, etc. Or to store a particular unit, select a unit in the map then use the unit's variable in the field (ex. Peon 0015 <gen>).
"Store Unit" Field Values
- Store Unit (The field wherein your selected unit will be stored) as Label (The unit's label in a category. You can type any) of Category (The category wherein the label will be saved) in (Last Created Game Cache). You can also change it's value like a Game Cache variable or simply last created game cache.

Game Cache - Store Real
- Same as 'Store Unit' but more different. You'll have to store a Real number this time. A Real number is a decimal (ex. 1.00, 1.25, 2.79, etc.).
"Store Unit" Field Values
- Same as the 'Store Unit' fields, but the object stored is a Real number this time. Also create individual categories for the values.

Game Cache - Store Integer
- Same as 'Store Unit' but much more different. You'll have to store an Integer this time. An Integer is a non-decimal or plain number. (ex. 1, 2, 3, 4, 5, etc.).
"Store Unit" Field Values
- Same as the 'Store Unit' fields, but the object stored is an Integer this time. Also create individual categories for the values.

Game Cache - Store Boolean

- Same as 'Store Unit' but much more different. You'll have to store a Boolean value this time. A Boolean value is a value that associates with events and conditions. (ex. 'A unit enters Region 001' then follows the condition 'Triggering unit is a Hero equal to True'. The Boolean value is set to true, so the unit that enters Region 001 should be a hero. If the condition is met, then the actions will be initiated).
"Store Unit" Field Values
- Same as the 'Store Unit' fields, but the object stored is an Integer this time. Also create individual categories for the values.

Game Cache - Restore Unit Facing Angle
- Restores a unit 'Label' from a created Category in a game cache. This action restores or loads a stored unit for a player in a region facing a particular facing angle. The angle is shown in degrees.

Game Cache - Restore Unit Facing Point
- Same as the 'Restore Unit Facing Angle' action. But the unit loaded this time faces a region, not the facing angle itself.

Game Cache - Reload All
- Reloads all game cache from the computer's disk.

Game Cache - Clear Game Cache
- Clears all labels of all categories in a game cache.

Game Cache - Clear Category
- Clears all labels of a specific category in a game cache.


Saving heroes using Game Caches
If you are making an RPG map, then this tutorial will definitely be the best support. If you create an RPG game most likely selecting a hero or a builder or anything, you should create a trigger that saves objects, yet it is not initially on,
with the 'initially on' checkbox unchecked. Once your hero is selected, the trigger will be turned on using 'Trigger - Turn On (The name of the trigger). You can make many events. Here are 2 examples of triggers that can be used in saving objects.

Here are Game Caches for the impatient mappers. Try this in an empty map:

Code:
Examples:
Save Hero Typing save
[COLOR=Gray] Events
   Player - Player 1 (Red) types a chat message containing -save as An exact match
 Conditions
   ((Triggering player) controller) Equal to User
 Actions
   Game Cache - Create a game cache from Game Cache Demo.w3v
   Set GameCache = (Last created game cache)
   Unit Group - Pick every unit in (Units owned by (Triggering player)) and do (Actions)
    Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                ((Picked unit) is A Hero) Equal to True
            Then - Actions
                Game Cache - Store (Picked unit) as Heroes of SavedHeroes in GameCache
                Trigger - Turn on Load Hero <gen>
                Unit - Remove (Picked Unit) from the game
            Else - Actions
                Do nothing[/COLOR]

In the second trigger you'll have to place a Circle of Power of any size and then create a region in the circle, particularly named
'Save Hero Circle' in my demo map.

Code:
Save Hero Enter Region
[COLOR=Gray]Events
   Unit - A unit enters Save Hero Circle <gen>
Conditions
   ((Triggering unit) is A Hero) Equal to True
Actions
   Game Cache - Create a game cache from Game Cache Demo.w3v
   Set GameCache = (Last created game cache)
   Game Cache - Store (Triggering unit) as Heroes of SavedHeroes in GameCache
   Unit - Remove (Triggering Unit) from the game
   Trigger - Turn on Load Hero <gen>[/COLOR]
NOTE: After saving a hero, you'll have to create a trigger that turns on the load hero trigger when the hero dies. It isn't
applied in this area of the tutorial. It'll be discussed later

You can also create an enabled but not intitially on trigger that loads the unit in a game cache. Here's an example.

Code:
Load Hero
=Events
   Player - Player 1 (Red) types a chat message containing -load as An exact match
=Conditions
   ((Triggering player) controller) Equal to User
=Actions
   Game Cache - Restore Heroes of SavedHeroes from GameCache for Player 1 (Red) at (Center of Load Game <gen>) facing Default building facing
   Game - Display to (All players) the text: It works!!

You'll see your newly loaded hero with the same hp, mana and attributes unlike before!! That's only for beginners. More types
will be discussed later.

Advanced Game Cache Techniques:
Highly advanced game cache techniques are shown here. Those who want to save more than units and other techniques, are here. Two
detailed techniques are shown.

1) Saving an Army then Loading it again.
It works the same way as of saving a single hero, but much more special and tougher. You'll need to create an army and then
create triggers the same way you create a trigger to save a hero. You'll need a bunch of these triggers if you have a bigger
army. To make things quicker, try using the action "Unit Group - Pick every unit in (Function) and do Action".
Create a trigger that loads units similar to above, still not initially on. Create a large region for the army to be restored
and make sure nothing is in it. You can then make events to load the army. You can then see your army with the same units and
attributes as of before you stored them.
2) Saving a Whole Town
The most difficult technique where you'll have to create a town that contains lots of units, buildings and heroes.
This is totally difficult and takes minutes to do it, but it gives a great impact to your map. You'll save your whole
town with all the units and buildings. You'll have to load those units just like above. But this you'll need to restore
each unit exactly to it's position after the objects have been saved. If your town is large, you'll have to create a dozen
triggers to complete the job. After these things, put creeps near your town and test it. Save your town and, watch the creeps
crush your town. Once nothing is left, do something to load the town like typing -load. You'll see the town back again.

ADDITIONAL TUTORIALS
1) How to save heroes and load them to another map
This is a trigger where in you will save the used hero in the currently played map. I use the hero thrall. You also need a variable.

You can use any event..
Code:
Save Thrall
    Events
        Magtheridon 0019 <gen> Dies
    Conditions
    Actions
        Game Cache - Create a game cache from Lvl1Game.w3v
        Set HeroCache - (Last Created Game Cache)
        Game Cache - Store Thrall 0001 <gen> as Thrall of Lvl1 in HeroCache
        Game Cache - Save HeroCache

Then you'll make another trigger in another map to load the hero in the previous map. Always save a game cache before loading it. You need another variable in the other map. In this trigger there are also additional actions like learning skills. I've got it in a campaign map using WinMPQ, opened the map and saw the triggers:)

Code:
Load Thrall in Lvl2Game
    Events
        Elapsed game time is 5.00 seconds
    Conditions
    Actions
        Game Cache - Restore Thrall of Lvl1 from (Last created game cache) for Player 1 (Red) at (Center of ThrallLoad <gen>) facing 360.00
        Set Thrall = (Last restored unit)
        If (Thrall Not equal to No unit) then do (Skip remaining actions) else do (Do nothing)
        -------- Create Default Hero --------
        Unit - Create 1 Thrall for Playa1 at (Center of ThrallLoad <gen>) facing 350.00 degrees
        Hero - Set (Last created unit) Hero-level to 4, Hide level-up graphics
        Hero - Learn skill for (Last created unit): Orc Far Seer - Far Sight
        Hero - Learn skill for (Last created unit): Orc Far Seer - Chain Lightning
        Hero - Learn skill for (Last created unit): Orc Far Seer - Chain Lightning
        Hero - Learn skill for (Last created unit): Orc Far Seer - Feral Spirit
        Set Thrall = (Last created unit)
-------------------------------------------------------------------------
Tutorial Summary
I hope these things have polished some of your triggering skills especially in creating Game Caches.
You can download my demo map about game caches by going to the URL:
http://www.epicwar.com/maps/7611/

I was kind of rushing to make the map so the author names are not made properly.

Now i added a free download for my demo map:

Download Now!

Written by jonadrian619
 

mase

____ ___ ____ __
Reaction score
154
Yea I should.
To distingush the titles, but the title should also be bigger and underlined.
Also, use the [ code ] [/ code ] (WITHOUT SPACES) BBCodes for your triggers. They are very hard to read...

IE:
Code:
this is the [code] BBCode
 

2-P

I will work hard tomorrow
Reaction score
325
I can't see a reason for multiple game caches. You only need to create one game cache once at the map initialization or after the map was loaded.

Would be helpful if you add a part on how to use the game cache to move stuff from on map to another.
 

SFilip

Gone but not forgotten
Reaction score
633
> I can't see a reason for multiple game caches.
AFAIK there is a certain (rather high) limit for the amount of data you can store in a single cache. In other words there is a good reason you might want to do that, but there is probably no need (at least if you're making an average map/campaign).

Anyway the tutorial...
1. Attach your demo map to the post itself please...IMO these tutorials should have as little external links as possible.
2. Use the CODE tags.
3. If you know about it you might as well mention the Local Handle Vars system - a must-have in order to make complex spells MUI.
 

The Helper

Necromancy Power over 9000
Staff member
Reaction score
1,698
Actually, attachments work great if people read the tutorial from the forum however if a user gets to the tutorial from here

http://world-editor-tutorials.thehelper.net/cat_usersubmit.php

the attachment will not show up on the tutorial rather the user would have to click to comment on the Tutorial then they could see the attachment. In all cases, once a Tutorial makes it into the Repository, it is best to have external links because they will be accessible in all the views the Tutorial will be seen in.
 

SFilip

Gone but not forgotten
Reaction score
633
Well he can link to the attachment somewhere in the post I guess.
The reason why I'm against external links is because the host site might simply go down (or the map may simply get deleted if they for example decide to get rid of the demos like wc3sear.ch now does if I'm not mistaking) and no one would actually notice it...the people that read it usually don't care to report broken links, they simply live without the demo which might as well be useful to someone.
 

Vnbear

Active Member
Reaction score
12
Campaign

Could you please include the tutorial on how to move heroes/units using game caches from 1 map to another?
 
G

G1thy4nk1

Guest
Great Work!, now all i need is a Game Cache Tutorial about....

1. Loading Gold from the last map ive played.

2. Loading Quests and Quest Triggers from the last map.

Im mostly confused about the Quest Caches because a quest can only be done in a Single map while moving to another map would be an idiotic (intellegent or wise) thing......
 
M

MotaReaper

Guest
Trouble

could you send me a code sample to save 4 heroes in a
custom campaign??? I'm from Portugal

I've tried everything...
I used your tutorial, others, even opened the demo campaign and exported the triggers... Nothing works.

I've made AI,terrain,cinematics,quests,history,8 levels including a bonus level.
just that little annoying thing... :banghead:

[email protected]

I'll wait for an answer.
 

Sim

Forum Administrator
Staff member
Reaction score
534
Posting a tutorial with triggers without CODE tags is a no-no. Especially when you have loops and if-then-else statements :p

Anyways. This proves to be useful. With some work on general outlook you can come up with something nice. Because at the moment, sorry but it is ugly. Ugly colors, no tags and titles too small. Try to have Centered text also, it looks good.

Good luck ^^
 

jonadrian619

-___-
Reaction score
240
I'm working in new topics and new tutorials about the game cache. I'm still working on it because it's big and there are many tutorials to make.

The next time these following tutorials will be added to this thread:

- Saving multiple heros and moving them in another map
- Saving resources and loading them again
- Saving Quests in a Cache

Originally Posted by Vnbear
Could you please include the tutorial on how to move heroes/units using game caches from 1 map to another?

The complete tutorial will also be included.

Ok, see you next time Im currently working on the new tutorials.....
 

jonadrian619

-___-
Reaction score
240
Almost done in the extra game cache tutorials. Some difficulty going on. Maybe a couple of days from now the tutorials will be posted in this same thread.....
 
G

G1thy4nk1

Guest
I'm working in new topics and new tutorials about the game cache. I'm still working on it because it's big and there are many tutorials to make.

The next time these following tutorials will be added to this thread:

- Saving multiple heros and moving them in another map
- Saving resources and loading them again
- Saving Quests in a Cache

Thank you
 

jonadrian619

-___-
Reaction score
240
Brand New game cache tutorials in April 2007 (version 2)

New tutorials will be added for version 2. Here are the tutorials.

- Saving/Loading integers
1) Hero Experience
2) Resources
3) Other tutorials associated with loading integers
- Saving/Loading Real
1) Time of Day
2) Other tutorials associated with loading Real values
- jonadrian619's customized Save/Load code for RPG's(there might be other tut. about Save Load codes, but this one is different.)
 
F

Flame_Emblem

Guest
Great Tutorial But Can you Possibly Make it Like The Rpg Save and Loads Where you Can Save The Hero does Not Dissapear You have a Code That Loads Him When You Play Again?I Find This To Be The Only Tutorial On This That I Can Really Understand
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
A Game Cache is not a Save/Load code. Game Caches are not universal; ie., they are only saved on one computer. A Save/Load code works because nothing is really being 'saved'. It just gives you a code that the game can read and reconstruct into a hero (or whatever).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top