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
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 241
Joined: Wed Nov 27, 2013 3:27 pm

How to immobilize this belgian unit?

Post by Kossatx »

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
Sergeant - 7.5 cm FK 16 nA
Sergeant - 7.5 cm FK 16 nA
Posts: 241
Joined: Wed Nov 27, 2013 3:27 pm

Re: How to immobilize this belgian unit?

Post by Kossatx »

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”