Hooray, it seems to have worked! Thank you.
I've made some slight modifications to the function; I hope it's still correct.
function checkGrok()
while (gro==0) do
sleep(10);
if (IsObjectExists("Grok")==nil) then
gro=1;
SetObjectiveState("Sec17", 3, 1);
sleep(3);
...
end;
sleep(5);
end;
sleep(5);
end;
startThread(checkGrok);
Auto-translated