Page 1 of 1

[Fixed] "Iron Hand" scenario Lua error

Posted: Tue Mar 02, 2021 5:33 pm
by Zahar00
Hey,

I'm just starting to play it, and it generally works, but I got this error:



Lua script execution error: [string "Game_HourlyActions"]:2: attempt to call a nil value (global 'WeatherReportIsDue')

When I finish it, I will let you know if there are any other bugs...

RE: "Iron Hand" scenario Lua error

Posted: Tue Mar 09, 2021 3:52 am
by WSBot
0014443

RE: "Iron Hand" scenario Lua error

Posted: Thu Apr 29, 2021 5:27 pm
by Rory Noonan
I've tried to reproduce this a few times without any success. Do you have a save file showing the issue?

RE: "Iron Hand" scenario Lua error

Posted: Sat May 01, 2021 3:37 pm
by KnightHawk75
Rory, is it possible you have a version of Iron Hand that hasn't actually shipped with the game or an update yet?

I can repo it with my local copy last modified 9/18/2020 (attached).
If you let it run for an hour, at 17:00Z you should get the issue and the reported errors in the exception log and the message log.

Function WeatherReportIsDue does not exist as function in the scene setup code (nor in the \lua\iron hand\ files for the scene, not that they're used), so the hourly event (Game_HourlyActions) that runs that calls it fails, that error then causes WeatherReportRUS to not run as well, and there is also a line to call CleanUpIdleCivilianShips() that never runs cause of it - but it too would fail as there is no such function. Additionally in LuaInit there is a pointless call to ScenEdit_RunScript('DeveloperMode.lua'), a file which does not exist, it doesn't matter other then the error getting logged.

The follow appears to be missing from LuaInit Action (based on other scenes):

Code: Select all

 function WeatherReportIsDue()
 	local result = false
 	local hourZulu = TimeIs().hour
 	local hourLocal = hourZulu + scenarioZuluOffset
 	if hourLocal %6 == 0 then
 			result = true
 	end
 	return result
 end

Code: Select all

function CleanUpIdleCivilianShips()
 	local unitList = VP_GetSide({side='Civilian'}).units
 	local numberOfCivilianUnits = #unitList
 	local numberOfUnitsDeleted = 0
 	for k,v in ipairs (unitList) do
 		local unit = ScenEdit_GetUnit({guid=v.guid})
 		if (unit.course[1] == nil or unit.speed == 0) and 
 			unit.type == 'Ship' then
 			ScenEdit_DeleteUnit({guid=v.guid})
 			numberOfUnitsDeleted = numberOfUnitsDeleted + 1
 		end
 	end
 
 	if DebugModeIsOn() and numberOfUnitsDeleted > 0 then
 		ScenEdit_SpecialMessage('playerside','Civ_Cleanup fired. <BR>Initial civilian Units: 
 '..numberOfCivilianUnits..' <BR>;Civilian units cleaned up: '..numberOfUnitsDeleted)
 	end
 end
 

I've tried adding the above and removing the developermode.lua call, and scene then runs without issue and you get the weather reports as intended.

RE: "Iron Hand" scenario Lua error

Posted: Tue May 04, 2021 3:08 pm
by Rory Noonan
Very possible! Save files save the back and forth, but there's no use hassling you about it [:)]

I've updated this file with the missing functions but have left the developer mode call in (it's there for a reason); when running outside of the console at scenario start this doesn't cause any practical issues but it does leave a trace in the error log.

The improvements to the Lua API mean I can actually do away with that DeveloperMode.lua file and just pass global variables before I open up the .scen files to work on them. The next major update will have this applied across all standalone scenarios.

Thanks for following up on this for Zahar00