Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation
This topic is the discussión abut the function Preload. You can see all the information about this function keyword HERE.

[functions] Preload No New Posts Jassdoc

Started by
City17

0 Members and 1 Guest are viewing this topic.

[functions] Preload
on: April 11, 2022, 09:14:53 PM

It does two things:
1) Try to read the file, if "Allow Local Files" is enabled then also searches in the game folder
2) Append filename to preload buffer

The game only reads these files, does not load them. The reading is done in a separate thread and does not freeze the game. One file is not read twice, no matter how often you call Preload().

Trick: It does not escape double-quotes " on purpose. It is possible to inject custom code in Preload files this way:
Code: Lua
  1. PreloadGenClear()
  2. PreloadGenStart()
  3. Preload(' ")\ncall otherFunction("123")\n//')
  4. PreloadGenEnd("its-a-feature.txt")
Results in the following preload file code:
Code: jass
  1. function PreloadFiles takes nothing returns nothing
  2.  
  3.         call PreloadStart()
  4.         call Preload( " ")
  5. call otherFunction("123")
  6. //" )
  7.         call PreloadEnd( 754.6 )
  8.  
  9. endfunction


Game folder:
Reforged: Warcraft III\_retail_\somefile.txt, instead of _retail_ there's also a _ptr_ game version currently.
Classic: ?

Mini tutorial:
What are Preload files?
Preload files instruct the game to pre-read a file/resources to avoid freezes/stutter during gameplay. It's done to move the file into OS cache. Blizzard used preload files to load all required files at map init. See blizzard.j or campaign maps.

Create a preload file
Code: Lua
  1. PreloadGenClear()
  2. PreloadGenStart()
  3. -- call Preload("filename.ext") as often as you need, one call per file you add
  4. Preload("Textures\\Knight.blp")
  5. PreloadGenEnd("MyPreloadFile.txt")

How to run a preload file
This must be done manually:
Code: Lua
  1. Preloader("MyPreloadFile.txt")

Lua code in preload files?
It is possible although in a very hacky way, described here. You need to use "//! beginusercode" to start a section containing Lua code and end it using "//! endusercode". It works because the code is transpiled on the fly with Jass2Lua.

See: PreloadEnd, PreloadStart, PreloadRefresh, PreloadEndEx, PreloadGenClear, PreloadGenStart, PreloadGenEnd, Preloader
« Last Edit: April 16, 2022, 03:38:20 AM by City17 »



 

Started by moyack

Replies: 3
Views: 3637
Jassdoc

Started by grim001

Replies: 0
Views: 1140
Codes & Snippets

Started by Jedi

Replies: 5
Views: 14206
General Jass Discussion

Started by moyack

Replies: 40
Views: 56816
Jass Theory & Questions

Started by AGD

Replies: 1
Views: 7597
Codes & Snippets
Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...