Jump to content

Recommended Posts

Posted (edited)

Similar logic works well elsewhere in the script but for some reason which I cannot figure out this section of code appears to bomb out on the Unit.getByName line. I've been rehashing it for hours now and got nowhere. The debug line just before correctly reports that redtemplate has the value of string GCIred1. Code further on in the function appears to be executed judging by other messages but the for loop seems to end the moment it hits the getByName.

 

line from dcs.log

00071.266 INFO SCRIPTING: redtemplate = GCIred1

 

but then it goes into the Unit.getByName(redtemplate) and never gets further as I don't ever see the next debug message reporting the value of unitgci.

 

As I said very similar logic is happening in the CAP spawning section of the script and that works fine. There is definitely an aircraft set to late activation on the map with the pilot = GCIred1. As far as I know the pilot = unit name for an aircraft.

 

Any ideas or can someone spot the problem?

 

function getinterceptorairborne(color)

local interceptorside = color

local grouptable = {} --XX7

local redtemplate = "" --XX7

local bluetemplate = "" --XX7

local inttypetable = {} --XX7

local unitgci = nil --XX7

local grpunitgci = nil

local grpgciname = ""

--XX create new local var numintCAPgrps to replace numberofCAPgroups

local numintCAPgrps = 0

if interceptorside == 'red'

then

numintCAPgrps = numberofredCAPgroups --XX replace numintCAPgrps

 

--XX7 >>

for idy = 1, 4 do

redtemplate = "GCI"..interceptorside..idy

Debug("redtemplate = "..redtemplate, interceptorside)

unitgci = Unit.getByName(redtemplate)

Debug("unitgci = "..unitgci, interceptorside)

grpunitgci = unitgci:getGroup()

Debug("grpunitgci = "..grpunitgci, interceptorside)

grpgciname = grpunitgci:getName()

Debug("grpgciname = "..unitgci, interceptorside)

grouptable = mist.getGroupData(grpgciname)

inttypetable[idy]=grouptable["units"][1]["type"]

Edited by Stonehouse
Posted

Try inserting a "if unitgci" control block right after you assign it. If late activated it will be "nil" before activation (I think).

Posted

Unit.getByName question

 

I am guessing that you run this function in a timer, so google pcall to get the error message.

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Posted (edited)

Ok, will try both thoughts. I thought that getByName doco on the ED and hoggit wiki said specifically said it could be used on units not yet activated, have to go check because if you're right Ajax then I'll have to do things a different way.

 

<edit>

Ok it seems that as far as I can tell Unit.getByName should work on units yet to be activated. I think I have managed to get pcall working on the getinterceptorairborne function and the error being returned which I assume is due to the getByName statement is:

 

"attempt to call a table value"

which doesn't make a whole lot of sense to me at this moment. Any ideas?

 

<edit2> ok from some reading it appears it is somehow to do with it being inside a for loop.........really don't understand why though.

 

Is it because it is treating the for loop index as a table?? so when I concat it to the other bits it is like I am concatenating things to a table in this particular context?

Edited by Stonehouse
results
Posted

You are trying to use a Unit-type as a string, Try changing:

Debug("unitgci = "..unitgci, interceptorside)

into

Debug("unitgci = "..unitgci:getName(), interceptorside)

DCS AJS37 HACKERMAN

 

There will always be bugs. If everything is a priority nothing is.

Posted

Thanks Ragnar, I kind of coded around the problem in the end but this resulted in some fairly ugly code so I will revisit this part of the script and see if your suggestion solves the issue. I expect it will as late Saturday during testing I noticed that commenting out that debug line fixed a crash. Lol stuffed up by a dodegy debug line. Takes me back to Cobol days and trying to find the missing full stop. Which may or may not mean much to you depending on your age and IT experience. :D

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...