Jump to content

Recommended Posts

Posted

I'm working on the CAP GCI script and getting a failure in the following at the line where stucktime is calculated:

 

 

 

Debug("Debugmessage: Script stuck at cleanup 4a", airfieldside)

local unitspawntime = stuckunitstable[currentaircraftunitname] --XX4

local stucktime = 0 --XX4

if unitspawntime ~= nil then --XX4

Debug("Debugmessage: Script stuck at cleanup 4b", airfieldside)

stucktime = timer.getTime() - unitspawntime --XX4

Debug("Debugmessage: Script stuck at cleanup 4c", airfieldside)

end --XX4 <<

 

 

 

stuckunitstable is a table which records a unit's spawn time and the unit's name is the index. As you can see I am checking for nil values before trying to do the calc.

 

It used to work and I haven't changed this piece of code so I'm a bit puzzled why it should stop now unless there has been a bug or change in timer.getTime with the last couple of patches??

 

I do know it is the stucktime calc line as I see the 4b debug msg but never the 4c

 

Any ideas?

 

Thanks,

Stoney

Posted

Ok found it. It seems that I made a mistake in having this to delete a table entry somewhere else in the script:

stuckunitstable[currentaircraftunitname] = {}

changed it to

stuckunitstable[currentaircraftunitname] = nil

and it works.

 

I remember something to do with this in a recent AWACS script related post so will have to look it up and check what was said.

Posted

Thanks Ajax,

I'm still missing something fundamental here with how to "delete" a table entry. It seems like there are certain situations where setting

 

table[index] = nil

 

is correct and then others where

 

table[index] = {}

 

is correct.

 

I found that I actually broke the script by changing some of Snafu's statements where it was table[index] = {} to table[index] = nil. So I had to change them back. Very odd.

 

Does anyone know what the difference is and the rules for use?

 

Cheers,

Stonehouse

Posted

To delete a table entry, table[index] = nil is always correct.

 

But sometimes the rest of your code expects that table entry to be another table. It may expect operations like #table[index] (to get the length) or for k, v in pairs(table[index]) to work. In that case, instead of deleting the entry itself, you want to set it to an empty table instead, which you do with table[index] = {}.

  • Recently Browsing   0 members

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