Some advice on creating foldit lua scripts:

Create comments describing the script at the top of the code. Comments start with -- (two hyphens).

Sometimes, it is easier to start with closed brackets or functions, which means write () first and fill it in, or if using the for command, write:

for k=1,x do


first, and fill it in. This means, you will write commands from outside to inside. Doing it this way, you are always sure that your functions are closed properly.

Print status information using the print() function as the script runs.

Print the improvement the script made to the starting score when the script finishes, like this:

function test()
    local scoreStart = get_score()
    -- do stuff here
    print('Script complete. Score changed by: ', get_score() - scoreStart)

Do not ever work with the absolute best score. Working with the absolute best score prevents the user from trying your script on positions that aren't the absolute best. Instead, call this code at the beginning of the script and any time that you do something that might improve the score:

local scoreRecentBest = 0

function SetRecentBest()
    local score = get_score()
    if score > scoreRecentBest then
        scoreRecentBest = score
        print('New Best Score=', scoreRecentBest)

At the end of the script, call restore_recent_best() to get back to the best score since the start of the script. If the script needs to store some position that is not the best score since the script started, then it can call quicksave(1), and restore to that position with quickload(1).

Community content is available under CC-BY-SA unless otherwise noted.