LUA CTD in MFD script code (resolved)

wingnut

Donator
Donator
Joined
May 10, 2013
Messages
129
Reaction score
0
Points
16
I am trying to check whether the currently focused vessel is docked to the ISS in a ScriptMFD with the following Lua code.

It works fine when the vessel is actually docked to the ISS but Orbiter crashes when the vessel is undocked and I don't understand why. The crash does not occur when I remove the for loop from below code but executing parts of it in the Lua console works as expected (i. e. hv is nil if the vessel is not docked).
PHP:
function dockCheck()
	local result = false
	local v = vessel.get_focusinterface()
	local hv
	if v == nil then
		result = false
	else
		for i=0, v:get_dockcount() do
			hv = v:get_dockstatus(v:get_dockhandle(i))
			if hv ~= nil then
				hv = vessel.get_interface(hv)
				if hv:get_name() == "ISS" then
					result = true
					break
				end
			end
		end
	end
	return result
end
Can someone spot any problem within this code snippet?


Edit:
After sleeping this over I noticed where my error is in the code: the index of the first docking port is 0, hence the for loop was running out of bounds. Therefore I changed the loop to:
PHP:
for i=0, v:get_dockcount() - 1 do
 
Last edited:
Top