• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[General] [lua] Accessing war3map.lua via code

Status
Not open for further replies.
Hi folks,

I'm trying to access war3map.lua by code, i.e. loading particular lines or the whole thing into a string var during runtime.

My main goal is to achieve a better error handling. The main error handling funcs "pcall" and "xpcall" return error messages like "war3map.lua:7325: attempt to call a nil variable", but they don't give a hint on which line of code in which function sub-call has caused that error.
I know, I might extract war3map.lua with an MPQ-editor and manually open it, but I would really prefer to have the causing line printed, because it makes debugging so much quicker.

Is there any way to load the file content into a string?
My dream would be to have a function allowing me to do local s = GetWar3mapLua() :D .

Some threads on hive mention ways of loading external data (although war3map.lua is not really external) by using the Preloader() and Preload() natives and exploiting BlzGetAbilityTooltip(), but I neither understand how that method works nor how to achieve my goal with it.
Example Thread: Am I doing this codeless loading wrong?

Any advice is welcome!

Thanks in advance and best regards
Eikonium
 
Level 10
Joined
Mar 26, 2017
Messages
376
I do the preloading with this code;

Creating File
Lua:
local s = loadstring
PreloadGenStart()
Preload("\")\ncall BlzSetAbilityTooltip(1097690227,\""..s.."\",0)\nreturn//")
PreloadGenEnd("filename.pld")


Loading File
Lua:
Preloader("filename.pld")
loadstring = BlzGetAbilityTooltip(1097690227, 0)
BlzSendSyncData(...)

(last line is not needed for singleplayer)


The 'trick' of BlzSetAbilityTooltip is to save strings outside game sessions, but I don't think it's what you're looking for. You could rather use this application to make changes to the map script.

Instead of putting 'call BlzSetAbilityTooltip...' you'll have to write a function definition that overrides an existing function, save it into a file, and then activate the file using Preloader.

I don't know the exact syntax how to do that, but perhaps you can find out using trial and error, and looking at the code above.

And maybe look into this resource: Jass Hot Code Reload
 
Last edited:
Hmm, I honestly don't understand that code...

How would you load war3map.lua into a string var now? :D

Still, many thanks for outlining the method!

And maybe look into this resource: Jass Hot Code Reload
I don't understand a word of that thread, but looks like a solution to add more code to the map script during runtime? Seems to involve reloading the map script, but not necessarily loading it into a string var, which is what I'd like to do :)
 
Status
Not open for further replies.
Top