|Opened on:||Sunday, November 27, 2011 - 04:27|
|Last modified:||Thursday, August 9, 2012 - 21:00|
One of the problems with lua -- or at least the parts exposed to foldit -- is that it is single-threaded. There are many scripts that get around this by doing short operations (such as wiggle) and testing between each iteration. However, a recent article made it clear that the behavior of wiggle changes over time -- so doing 5 short wiggles is not the same as doing one longer one.
The same may be true for other functions (shake?), though this was not made clear in the article.
Ideally, one could have a separate thread watching the script and controlling its behavior. But the implementation of this might be complex. A simpler solution might be a "Continue_Wiggle()" function. All existing scripts that call wiggle would continue to function as they always have. But a new scripter could write
if someCondition then break end
This code could be made even simpler with the addition of a second function: init_wiggle(). That way subroutines could be written that call continue_wiggle(), leaving the calling routine to decide whether to reinitialize the wiggle algorithm.
Side note: There are a variety of other ways to implement this -- such as leaving a single call to wiggle, but have its behavior changed by the state of a continue_wiggle flag. (This might also be a checkbox in the UI).