Fandom

Foldit Wiki

Lua Script Advice

1,423pages on
this wiki
Add New Page
Comments0 Share

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

end

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)
end

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)
        reset_recent_best()
    end
end

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).

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.