I had an actor that started an idle sequence triggered from a dialogue tree. Up until yesterday he'd been just fine. Then he started getting a six or so second delay before doing anything. And the irritating thing was I hadn't really changed anything.
The catch was in the "really" of course. I have a large, complex function in a quest script - let's call it foo() and my quest fragment was something like
SSG_Quest_S q = GetOwningQuest() as SSG_Quest_Sq.foo(akSpeaker as actor, game.getPlayer(), true)
Anyway, I wanted to add some notification lines and traces to that, so I thought I'd encapsulate it in the main quest scripr
SSG_Quest_S q = GetOwningQuest() as SSG_Quest_Sq.salesman_foo(akSpeaker)
and have the quest script define:
function salesman_foo(actor a) foo(a, game.getPlayer(), true)endfunction
So I did that, and that extra function call cost me six seconds of lag. I put it back the way it was and the delay went way.
So I'm assuming that in general, calling Script.foo() from inside Script.bar() must suspend the script thread and give all the other running scripts a slice before resuming. Which is a little worrying.
I also don't understand why I don't get this sort of delay for utility functions called internally. I have code that loops over arrays calling multiple local functions on each element. If I lost the thread for each of those calls my code would take forever. So is there some other explanation for the delay in this case?
If not, how best to code around the problem? Big, multi-parametered functions would seem preferable to writing complex code in tiny fragment boxes. I just wish I understood why this one call suffered such a penalty when internal script calls usually seem so cheap.
What's best practice here?