Page 1 of 1

Lua code for adding markers [Solved]

Posted: Tue Jan 10, 2012 10:34 pm
by Fiodis
I'm trying to make a quick script that adds a marker arrow to a unit when that unit uses a certain weapon, and removes it when the unit uses the weapon again. Unfortunately I'm a bit rusty. I've gotten this far:
Hidden/Spoiler:
[code] IsEntityMarked = 0
mark = OnCharacterDispenseControllable(
function(character, controllable)
if GetEntityClass(controllable) == FindEntityClass("rep_bldg_inf_marker") then
charunit = GetCharacterUnit(character)
if IsEntityMarked = 0 then -- This is line 98.
MapAddEntityMarker(charunit, "hud_objective_icon", 3.0, 1, "YELLOW", true)
IsEntityMarked = 1
elseif IsEntityMarked = 1 then
MapRemoveEntityMarker(charunit)
IsEntityMarked = 0
end
end
end
)[/code][/size]
But the error log complains:
Hidden/Spoiler:
C:\BF2_ModTools\data_FTG\_BUILD\Common\..\..\..\ToolsFL\Bin\luac.exe: ..\..\common\scripts\FTG\FTGc_con.lua:98: `then' expected near `='
ERROR[scriptmunge scripts\FTG\FTGc_con.lua]:Could not read input file.ERROR[scriptmunge scripts\FTG\FTGc_con.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings

ERROR[levelpack mission\FTGc_con.req]:Expecting bracket, but none was found.
File : munged\pc\ftgc_con.script.req(1)...

ucft <--
ERROR[levelpack mission\FTGc_con.req]:Expecting bracket, but none was found.
File : munged\pc\ftgc_con.script.req(1)...

ucft <--

2 Errors 0 Warnings
As far as I can see, I've done nothing wrong - but I don't have much faith in my own analysis. Trying to attach the marker to the character, rather than the unit, had the same result.

Re: Lua code for adding markers

Posted: Tue Jan 10, 2012 10:41 pm
by Firefang
When the variable is in an If statement, it needs == instead of = to say "is equal to".

Code: Select all

if IsEntityMarked == 0 then

Re: Lua code for adding markers

Posted: Tue Jan 10, 2012 10:48 pm
by Fiodis
Ah yes, that should fix it. Thank you; I'll mark this solved.