Page 1 of 1

Tech crash

Posted: Thu Sep 24, 2020 4:49 pm
by Kossatx
Hi pals, any idea about this crash?

Code: Select all

[18:38:57][8472]game/game_research.lua:861(global HasUnitTech) game/game_research.lua:861: attempt to index field 'luaData' (a nil value)
[18:38:57][8472]Resume: false, std::exception: 'Lua Error:game/game_research.lua:861(global HasUnitTech) game/game_research.lua:861: attempt to index field 'luaData' (a nil value)'
[18:38:57][8472][C]:-1(global error) ai/ai.lua:0: std::exception: 'Lua Error:game/game_research.lua:861(global HasUnitTech) game/game_research.lua:861: attempt to index field 'luaData' (a nil value)'
This is the script:

Code: Select all

function HasUnitTech(unit, techName)

  -- Check if unit has it
  i = 1
  while unit.luaData.unitTechs[i] ~= nil do -- line 861
    -- Check if unit already has tech
    if unit.luaData.unitTechs[i] == techName then
      return true
    end
    i = i + 1
  end

  return false
end

Re: Tech crash

Posted: Thu Sep 24, 2020 6:45 pm
by Robotron
Difficult to say.

I assume this crash is from your personal modification of Potzblitz?

Please give me more info about the situation in the game:
1. when did that crash happen?
2. what turn is it
3. what is happening in the match

I'll need at least the whole logfile.

Re: Tech crash

Posted: Thu Sep 24, 2020 7:53 pm
by Kossatx
EDITED:

All the answers are YES, the crash happened in turn 42, while IA (Entente) attacking near Udine. An Italian Cavalry Corps attacking an Austrian Army Corps at hex 100, 34. I have tried to fix the crash, but I have no idea :idea:

Re: Tech crash

Posted: Thu Sep 24, 2020 8:14 pm
by Robotron
Where did that Italian cavalry come from?

Italy does not start with cavalry and AI never builds cavalry. Also there is no Spawnunit for italian cavalry in my mod.

That leaves YOU :mrgreen: as the source of the crash!

Where did you mod the script to have a cavalry spawn for Italy?

Show me that part in your script.

Re: Tech crash

Posted: Thu Sep 24, 2020 8:37 pm
by Robotron
I've had another idea: replace

function HasUnitTech

with this:

Code: Select all

function HasUnitTech(unit, techName)

	if unit.alive then
	  -- Check if unit has it
	  i = 1
	  while unit.luaData.unitTechs[i] ~= nil do
		-- Check if unit already has tech
		if unit.luaData.unitTechs[i] == techName then
		  return true
		end
		i = i + 1
	  end
	 
	end 

  return false
end

Re: Tech crash

Posted: Fri Sep 25, 2020 7:41 am
by Kossatx
It works! :D How have you learned to mod lua files so fine? In my variant of Potzblitz MOD Italy neither begins with Cavalry Corps, but IA build them sometimes. I think IA takes in account many variables of units.lua file to decide which units to build.

Re: Tech crash

Posted: Fri Sep 25, 2020 8:46 pm
by Robotron
I've never ever seen the AI build a cavalry corps but great the solution worked for you.
That's all that matters.
:D