Proper ':inarea' syntax(fixed) New problem

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
vettim89
Posts: 3668
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

Proper ':inarea' syntax(fixed) New problem

Post by vettim89 »

The following code give me this error: ERROR: [string "Console"]:5: Trying to invoke invalid method or an access an invalid index

Code: Select all

local doc=ScenEdit_GetKeyValue('doctrine')
local unit=ScenEdit_UnitX
local mult
if doc=='defense' then
  if unit:inarea({'DD 1', 'DD 2', 'DD 3', 'DD 4', 'DD 5', 'DD 6', 'DD 7', 'DD 8'}) then
  mult=5
  else
  mult=1
  end
elseif doc=='limited' then
  if unit:inarea({'LO 1', 'LO 2', 'LO 2', 'LO 3', 'LO 4', 'LO 5', 'LO 6', 'LO 7'}) then
  mult=5
  elseif unit:inarea({'DD 1', 'DD 2', 'DD 3', 'DD 4', 'DD 5', 'DD 6', 'DD 7', 'DD 8'}) then
  mult=3
  else
  mult=1
  end
else
  if unit:inarea({'FO 1', 'FO 2', 'FO 3', 'FO 4', 'FO 5', 'FO 5', 'FO 6', 'FO 7', 'FO 8'}) then
  mult=5
  elseif unit:inarea({'DD 1', 'DD 2', 'DD 3', 'DD 4', 'DD 5', 'DD 6', 'DD 7', 'DD 8'}) then
  mult=3
  else
  mult=1
  end
end
local points=10*mult
local score=ScenEdit_GetScore('USSR')
score=score+points
ScenEdit_SetScore('USSR',score,'NATO A/C Shot Down')
The scenario is set up for the player to chose which doctrine they wish to play: defensive, limited offensive, and full offensive. I want scoring to be based on the location of the destroyed unit based on the selected doctrine. I have forced the Lua script by feeding it an actual unit and doctrine and I still get the 'index' error. Obviously I have the syntax wrong. Any help?
Last edited by vettim89 on Sat Apr 23, 2022 1:22 am, edited 1 time in total.
"We have met the enemy and they are ours" - Commodore O.H. Perry
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Proper ':inarea' syntax

Post by KnightHawk75 »

unit:inArea

Case matters in Lua function/method/variable names. :D Been there got the t-shirt.
User avatar
vettim89
Posts: 3668
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

Re: Proper ':inarea' syntax(fixed) New problem

Post by vettim89 »

So using the proper syntax "InArea" fixed the script as far as it running in the console without error. However, the event is not working in game. I am wondering if the problem is that I am using SE_UnitX to access the destroyed unit. I am afraid that because it is a destroyed unit that its wrapper no longer exist to pass to the Lua script.

Does anyone know if this is correct or should I be looking for another problem?
"We have met the enemy and they are ours" - Commodore O.H. Perry
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Proper ':inarea' syntax(fixed) New problem

Post by KnightHawk75 »

vettim89 wrote: Sat Apr 23, 2022 1:26 am So using the proper syntax "InArea" fixed the script as far as it running in the console without error. However, the event is not working in game. I am wondering if the problem is that I am using SE_UnitX to access the destroyed unit. I am afraid that because it is a destroyed unit that its wrapper no longer exist to pass to the Lua script.

Does anyone know if this is correct or should I be looking for another problem?
If it's a destroyed trigger then the basic data should still be there in UnitX(), check if it's nil or not, if not nil print it and find out should be there like...

Code: Select all

local u = UnitX(); print('destroyed unit')
if u ~= nil then print(u); else print('UnitX was nil!'); end
destroyed unit
unit {
type = 'Facility',
subtype = '3005',
name = 'Antenna Tower - AM Radio',
side = 'Red',
guid = '4FH7PU-0HMH4U6GHF121',
class = 'Antenna Tower - AM Radio',
proficiency = 'Regular',
latitude = '31.8003941292558',
longitude = '-87.4269396168303',
altitude = '20',
heading = '0',
speed = '0',
throttle = 'FullStop',
autodetectable = 'True',
mounts = '0',
magazines = '0',
unitstate = 'Unassigned',
fuelstate = 'None',
weaponstate = 'None',
}
You'll at least exclude it as the issue if you see it's valid. Hard to say what else might be causing your issues without seeing it.
User avatar
vettim89
Posts: 3668
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

Re: Proper ':inarea' syntax(fixed) New problem

Post by vettim89 »

I have been playing with this and the Lua script runs perfectly if I feed it an existing aircraft in the console. When I run it in game feeding it the destroyed aircraft, it fails. So it does seem that UnitX() will not feed the wrapper of a destroyed unit into a Lua script. Bummer because I really wanted this functionality to be part of how this scenario is scored.

Have to contemplate how to do this. Perhaps using an inArea index on the firing unit. Is there a way to get that information? Wow I just looked - its SE_UnitY() using the 'caused by" case

Going to try it
"We have met the enemy and they are ours" - Commodore O.H. Perry
User avatar
vettim89
Posts: 3668
Joined: Fri Jul 13, 2007 11:38 pm
Location: Toledo, Ohio

Re: Proper ':inarea' syntax(fixed) LOL

Post by vettim89 »

or some moron wrote SE_UnitX vice SE_UnitX() :shock: :lol: :oops:

For the record: UnitX() will send the wrapper of a destroyed unit to Lua

<I'm just going to crawl away back into my hole now>
"We have met the enemy and they are ours" - Commodore O.H. Perry
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

Re: Proper ':inarea' syntax(fixed) LOL

Post by KnightHawk75 »

vettim89 wrote: Sat Apr 23, 2022 8:20 pm or some moron wrote SE_UnitX vice SE_UnitX() :shock: :lol: :oops:

For the record: UnitX() will send the wrapper of a destroyed unit to Lua

<I'm just going to crawl away back into my hole now>
:lol: No worries, happens to the best of us sometimes, glad you found/noticed the issue.
Post Reply

Return to “Lua Legion”