mrSkortch / MissionScriptingTools

Mission Scripting Tools for Digital Combat Simulator
GNU General Public License v3.0
190 stars 42 forks source link

Specifying string name does not work after latest DCS update #69

Closed techdr1ve closed 2 years ago

techdr1ve commented 2 years ago

Here are more details, I used the two latest versions of MIST, can't get it to work. Was working a long time (it's a CSAR POW Mod for DCS that I added using MIST)

Line that Errors out:

POW1MARKER.pos = Unit.getByName("NameOfUnit"):getPoint() -- This is the line that errored out, used to work or POW1MARKER.pos = Group.getByName("NameOfUnit"):getPoint() -- This is the line that errored out, used to work

I narrowed my error to this last line above either of the two.

Error from dcs.log: 2022-08-14 04:56:46.250 ERROR SCRIPTING: Error while handling event [string "C:\Users\username\AppData\Local\Temp\DCS.openbeta\/~mis00003EE0.lua"]:1060: attempt to index a nil value

Full Code Sample:

----create a orange marker for POW when released!
local myLog = mist.Logger:new('PRISONLOG')
POW1MARKER = {} ---this table is instantiated at the top of the code
csar.enableCSAROrangeCircles = True
csar.enableCSARForVIP = True
if csar.enableCSAROrangeCircles then    
     if csar.enableCSARForVIP then
           myLog:msg("D1")  
           POW1MARKER.pos = Unit.getByName("POW1"):getPoint() -- this is the line that errors out, worked b4
       --POW1MARKER.pos = _unit.getByName("POW1"):getPoint() -- tried this as well, doesn't work  
           --POW1MARKER.pos = _unit:getByName("POW1"):getPoint() -- tried this as well, doesn't work        
           --POW1MARKER.pos = Group.getByName("POW1"):getPoint() -- tried this as well, doesn't work                  
           myLog:msg("D2")  
           POW1MARKER.id = mist.marker.getNextId()
           myLog:msg("D3")  
           POW1MARKER.mType = 0
           myLog:msg("D4")  
           POW1MARKER.readOnly = 0
           myLog:msg("D5")  
           POW1MARKER.text = "POW1 Located Here!"
           myLog:msg("D6")  
           mist.marker.add(POW1MARKER)
           myLog:msg("D7")  
           POW1MARK_check = "YES"
           myLog:msg("D8")  
           POW1DEAD_check = "YES"  
           myLog:msg("D9")                
     end
end

myLog:msg("E")

dcs.log file messages: 2022-08-14 04:56:46.250 INFO SCRIPTING: PRISONLOG|1056: D1 2022-08-14 04:56:46.250 ERROR SCRIPTING: Error while handling event [string "C:\Users\username\AppData\Local\Temp\DCS.openbeta\/~mis00003EE0.lua"]:1060: attempt to index a nil value

mrSkortch commented 2 years ago

It is literally impossible for me to figure out the problem without more context. Full sample of what you are passing to whichever function is apparently buggy.

techdr1ve commented 2 years ago

I'm sorry to post only the one line b4, hopefully this above give you a clear picture of my error. Let me know how else I can explain it.

mrSkortch commented 2 years ago

Ok, so it is erroring on your code. I guess the obvious question is if there is a unit in the mission actually named "POW1"? Otherwise yeah it would error because you are using getPoint() on a nil object. Whenever you are getting an object it is a good idea to verify it actually exists before trying to do anything to it.

local u = Unit.getByName("POW1")
if u then
  POW1MARKER.pos = u:getPoint()
else
  myLog:msg("POW1 didnt exist")
end
techdr1ve commented 2 years ago

image

techdr1ve commented 2 years ago

I see what you're saying, yea definitely have POW1 in the unit name. Good idea to verify it exists as well I agree. POW1 is group name as well and have tried it without putting POW1 as the group name as well. Still errors.

Is it possible to verify that putting a string name in this function works on your end? u = Unit.getByName("UnitName")

Then I'll know if it's just me or it's a DCS or DCS to MIST issue at that point.

techdr1ve commented 2 years ago

This is actually a different issue than what I thought ... really it's marker.pos that cannot receive a point(). I'll open up another issue for it.