6 replies [Last post]
Offline
Joined: 11/26/2012
Groups: Go Science

Just wondering if there any LUA function to get the newly added shape complementarity (SC) score.

Or the other new metrics (SASA, DDG)

Something like:
getSC();
getSASA();
getDDG();

Offline
Joined: 12/27/2012
sort of...

There are some almost new metric functions. They'll tell you the bonus for each metric, but not the underlying measurement. The release that's now in devprev is supposed to allow graduated metrics, so the bonus can be proportionate to the measurement. Right now in main, it's either 1000 points or not for each metric. (The puzzle needs to be set up correctly to return these graduated bonuses.)

Check out the metric functions on the Foldit Lua Functions page.

The function metric.GetNames() returns a Lua table containing the names of metrics for the current puzzle. If the table is empty, there are no metrics. The code looks something like:

metz = metric.GetNames ()
if #metz == 0 then
print ( "no metrics found" )
else
for ii = 1, #metz do
print ( "metric " .. ii .. " = \"" .. metz [ ii ] .. "\", score = " .. metric.GetBonus ( metz [ ii ] ) )
end
end

There are two score-related functions, metric.GetBonus and metric.GetBonusTotal. GetBonus gets the bonus for one specified metric. Assuming you have the code above, the for loop could include the bonus:

for ii = 1, #metz do
print ( "metric " .. ii .. " = \"" .. metz [ ii ] .. "\", score = " .. metric.GetBonus ( metz [ ii ] ) )
end

The function metric.GetBonusTotal returns the total of all metrics.

The "metric" functions don't include the enable/disable functions you'll find under "filter". Instead, the function behavior.SetFiltersDisabled can be used to disable or enable all metrics and filters. With filters, recipes can disable or enable individual filters, but this isn't possible for metrics.

Unlike filters, metrics return a score (bonus) even when they're disabled. Calling "metric.GetBonus ( "DDG Metric" )" will return the bonus (if any) even when the metric is disabled. The call also appears to recalculate the metric, so it may be on the slow side.

The wiki page condition and metric control gets into the issue of enabling and disabling filters and metrics. It's a whole can of worms. Basically the idea is that you want to disable stuff for performance reasons, but then you want to enable again to make sure you don't miss out on something good. Especially for recipes, figuring out when you want to enable filters and metrics is strategically important.

Offline
Joined: 12/27/2012
moar...

I tried to link to the metric functions in the previous post, but the link doesn't seem to work consistently in Firefox, sometimes bouncing to filters instead. You can always just go to Foldit Lua Functions, then use the table of contents near the top. (It can take a moment to load.) The metric functions are currently #11 in the TOC. There are only three metric functions, described in the previous post.

Also, the original post had a list of function names provided by rav3n_pl. That list is now out of date, since the metric functions were added in early October 2020.

You can always get the current list of functions by running the following one-line recipe in Foldit:

help ()

To do that, you open the recipe editor via the notepad icon in the Foldit cookbook. Click on "New (ScriptV2)" at the bottom of the recipe editor window. You'll get a clean screen. Type "help ()" up at the top, then click "Run" down below. You'll get a list of all the commands in version 2 of the Foldit Lua interface. They'll be in the recipe output window, and also the scriptlog file, which is named scriptlog.default.xml by default and is located in c:\Foldit or wherever you have the game installed.

That "help()" command is actually the start of where the Foldit Lua Functions page comes from. You can also ask about a particular function, for example "help ( metric.GetBonus )". There's a semi-automated process that combines those steps, and the Foldit Lua Functions page is the result. (Careful observers may note that the output for "help ( metric.GetBonus )" is a little off, missing an opening paren.)

In addition to the big list of functions, each function also has a detail page, which is linked from the main list. So there's a page for metric.GetBonus and also one for metric.GetNames.

Offline
Joined: 11/26/2012
Groups: Go Science
Ok that's a lot more clear

Ok that's a lot more clear now, I didn't think to look at metric.GetBonus. Just gotta wait until the scores are proportional. Thanks LociOiling

Offline
Joined: 11/26/2012
Groups: Go Science
Just noticed that there was a

Just noticed that there was a blog post about this too:

https://fold.it/portal/node/2010472
Using recipes with Metrics

Offline
Joined: 12/27/2012
still moarrrr......

The "binder metrics" wiki page has been renamed to just plain Metric. Also, pretty much everything on that page had changed since it was written. There's new text and some new images, and I'm hoping that fixed everything.

I see that puzzle 1913 is supposed to have graduated metrics, but I haven't tried it.

Offline
Joined: 12/06/2008
Groups: Contenders
A quick "thank you"....

A quick "thank you", Loci, for all the documentation you've provided here and in the wiki. It's my intent to learn scripting (and make some awesome recipes!), and I am certain that your work here will help me grasp the necessary knowledge quickly and easily.