Stonehouse Posted December 30, 2014 Posted December 30, 2014 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
Stonehouse Posted December 30, 2014 Author Posted December 30, 2014 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.
ajax Posted December 30, 2014 Posted December 30, 2014 That was in dOoOm's thread: http://forums.eagle.ru/showthread.php?t=133953
Stonehouse Posted December 30, 2014 Author Posted December 30, 2014 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
FSFIan Posted December 30, 2014 Posted December 30, 2014 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] = {}. DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
Stonehouse Posted December 30, 2014 Author Posted December 30, 2014 Thanks Ian. Best wishes for the New Year! Have to catch up on that stuff with you and XCom in 2015 once Edge has arrived.
Recommended Posts