How to immobilize this belgian unit?

A forum to discuss custom scenarios, campaigns and modding in general.

Moderators: Slitherine Core, The Lordz

Post Reply
Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

How to immobilize this belgian unit?

Post by Kossatx » Sun Apr 28, 2019 10:45 pm

Hi! I'm trying to immobilize in Brussels only belgian units that move in the hex. I've written this code, but the game crashes :cry: Any idea?

Code: Select all

local belgium = game:GetFactionById(6)
local Brussels = game:GetHex(86, 26)
if Brussels.unit ~= nil
	and unit.hex ~= nil
	and unit.hex.x == 86
	and unit.hex.y == 26
	and unit.type == Unit.LAND
	and hex.unit.faction.id == 6 then
		unit.mp = 0
end	

Code: Select all

[00:40:32][4640]Phase start: central_powers
[00:40:32][4640]**************
[00:40:32][4640]**************
[00:40:32][4640]SIGINT PHASE
[00:40:32][4640]**************
[00:40:32][4640]**************
[00:40:32][4640]--------------------------------------/////////////////-------------------------------CP SIGINT PHASE
[00:40:32][4640]game/game_supply.lua:609(global SetUnitMovePenalty) game/game_supply.lua:609: attempt to index global 'hex' (a nil value)
[00:40:32][4640][C]:-1(method Start) std::exception: 'Lua Error:game/game_supply.lua:609(global SetUnitMovePenalty) game/game_supply.lua:609: attempt to index global 'hex' (a nil value)'

Kossatx
Administrative Corporal - SdKfz 251/1
Administrative Corporal - SdKfz  251/1
Posts: 132
Joined: Wed Nov 27, 2013 3:27 pm

Re: How to immobilize this belgian unit?

Post by Kossatx » Mon Apr 29, 2019 10:19 pm

I've already fixed the crash writting "unit.faction.id" instead of "hex.unit.faction.id":

Code: Select all

local belgium = game:GetFactionById(6)
local Brussels = game:GetHex(86, 26)
if Brussels.unit ~= nil
	and unit.hex ~= nil
	and unit.hex.x == 86
	and unit.hex.y == 26
	and unit.type == Unit.LAND
	and unit.faction.id == 6 then
		unit.mp = 0
end	

Post Reply

Return to “Commander the Great War : Mods & Scenario Design”