Hello there !
I am trying to override global functions, like those created by World Editor when saving the map script.
I was hoping to use the context to modify them.
I did a test with several of them, including "main", "config" or "InitBlizzard" :
Note that the only thing I changed from the original functions is the last 3 lines of the "main" function to call my custom Init function rather than InitGlobals, InitCustomTriggers and RunInitializationTriggers that are useless in my map.
The problem is, when I try to do this, and test the map from WE, the game starts up, but hangs on the lion logo, the map not loading anything, so I guess it means the original global functions are overridden, but my custom versions like newmain do not run.
Also note that unlike in @Bribe 's [Lua] Global Initialization, I don't want to run the original function to just add mine, but I would rather like to gain full control of what is loaded with my map, to prevent it from loading useless things.
I know I can do this by editing the wc3map.lua script directly, but I would then lose the ability to work on my map from the World Editor.
So, what have I done wrong ?
EDIT 1: oops seems like I once again have done a typo
EDIT 2: ok, after removing the io. from io.config, the map loads, but then nothing happens when the map is started (or rather the screen is black like full Fog Of War and only the preliminary UI shows)
I am trying to override global functions, like those created by World Editor when saving the map script.
I was hoping to use the context to modify them.
I did a test with several of them, including "main", "config" or "InitBlizzard" :
Lua:
do
local oldmain = main
main = function()
return newmain()
end
local oldconfig = io.config
config = function()
return newconfig()
end
local oldInitBlizzard = InitBlizzard
InitBlizzard = function()
return newInitBlizzard()
end
function newmain()
SetCameraBounds(-8192.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), -8192.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM), 8192.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), 8192.0 - GetCameraMargin(CAMERA_MARGIN_TOP), -8192.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), 8192.0 - GetCameraMargin(CAMERA_MARGIN_TOP), 8192.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), -8192.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM))
SetDayNightModels("Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl", "Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl")
SetWaterBaseColor(0, 0, 255, 255)
NewSoundEnvironment("Default")
SetAmbientDaySound("IceCrownDay")
SetAmbientNightSound("IceCrownNight")
SetMapMusic("Music", true, 0)
InitBlizzard()
Init()
end
function newconfig()
SetMapName("TRIGSTR_003")
SetMapDescription("TRIGSTR_1139")
SetPlayers(5)
SetTeams(5)
SetGamePlacement(MAP_PLACEMENT_TEAMS_TOGETHER)
DefineStartLocation(0, -2752.0, 6528.0)
DefineStartLocation(1, 6528.0, 2752.0)
DefineStartLocation(2, 2752.0, -6528.0)
DefineStartLocation(3, -6528.0, -2752.0)
DefineStartLocation(4, 64.0, 64.0)
InitCustomPlayerSlots()
InitCustomTeams()
InitAllyPriorities()
end
function newInitBlizzard()
-- Set up the Neutral Victim player slot, to torture the abandoned units
-- of defeated players. Since some triggers expect this player slot to
-- exist, this is performed for all maps.
ConfigureNeutralVictim()
InitBlizzardGlobals()
InitQueuedTriggers()
InitRescuableBehaviorBJ()
InitDNCSounds()
InitMapRects()
InitSummonableCaps()
InitNeutralBuildings()
DetectGameStarted()
end
end
Note that the only thing I changed from the original functions is the last 3 lines of the "main" function to call my custom Init function rather than InitGlobals, InitCustomTriggers and RunInitializationTriggers that are useless in my map.
The problem is, when I try to do this, and test the map from WE, the game starts up, but hangs on the lion logo, the map not loading anything, so I guess it means the original global functions are overridden, but my custom versions like newmain do not run.
Also note that unlike in @Bribe 's [Lua] Global Initialization, I don't want to run the original function to just add mine, but I would rather like to gain full control of what is loaded with my map, to prevent it from loading useless things.
I know I can do this by editing the wc3map.lua script directly, but I would then lose the ability to work on my map from the World Editor.
So, what have I done wrong ?
EDIT 1: oops seems like I once again have done a typo
EDIT 2: ok, after removing the io. from io.config, the map loads, but then nothing happens when the map is started (or rather the screen is black like full Fog Of War and only the preliminary UI shows)
Last edited: