Icon representing a recipe

Recipe: Co lapse's Settle Lua version c

created by LociOiling

Profile


Name
Co lapse's Settle Lua version c
ID
104150
Shared with
Public
Parent
Co lapse's Settle Lua version a
Children
Created on
November 25, 2020 at 22:05 PM UTC
Updated on
November 25, 2020 at 22:05 PM UTC
Description

Refined Lua conversion of Co lapse's Settle, https://fold.it/portal/recipe/1773

Best for


Code


--[[ Co lapse's Settle Lua version c Lua conversion of Co lapse's Settle from 2009 https://fold.it/portal/recipe/1773 See "GUI to Lua - converting Co lapse's Settle" on the wiki https://foldit.fandom.com/wiki/GUI_to_Lua_-_converting_Co_lapse%27s_Settle The wiki page "GUI to Lua - refining Co lapse's Settle" https://foldit.fandom.com/wiki/GUI_to_Lua_-_refining_Co_lapse%27s_Settle covers "version c" of the recipe. This version converts the GUI commands to their Lua counterparts in a straightforward way, with nothing added. The major trick demonstrated here is using for loops to emulate the "by stride" option of the segments ingredient. A future version will refine the approach. version a - 2020/11/24 - LociOiling version b - 2020/11/24 - LociOiling (unpublished) + local wiggle all segments between freezes (SelectRange) + added stopwatch (STW) to simplify timing version c - 2020/11/25 - LociOiling + create FreezeLWS function to handle repeated code + select a range of one or more segments, not just one segment ]]-- ReVersion = "Co lapse's Settle Lua version c" STW = { -- STW--STW--STW--STW--STW--STW--STW--STW--STW--STW--STW--STW--STW --[[ stopwatch package version 0.3 thanks to Paul Dunn for the time formatting logic ]]-- wat = {}, start = function ( self, tag ) if tag == nil or tag == "" then tag = "default timer" end self.wat [ tag ] = { tag = tag, date = os.date (), time = os.time () } print ( tag .. " started at " .. self.wat [ tag ].date ) end, stop = function ( self, tag ) if tag == nil or tag == "" then tag = "default timer" end local wot = self.wat [ tag ] if wot ~= nil then -- -- thanks to Paul Dunn for the timekeeping logic -- local seconds, minutes, hours, days, remainder, result local elapsed = os.difftime ( os.time (), wot.time ) days, remainder = math.modf ( elapsed / ( 24 * 60 * 60 ) ) hours, remainder = math.modf ( remainder * 24 ) minutes, remainder = math.modf ( remainder * 60 ) seconds, remainder = math.modf ( remainder * 60 ) result = string.format ( "%02id:%02ih:%02im:%02is", days, hours, minutes, seconds ) print ( tag .. " stopped at " .. os.date () .. ", " .. elapsed .. " seconds elapsed" ) print ( "clock time = " .. result ) return elapsed else print ( "stopwatch \"" .. tag .. "\" not found" ) end end, } -- STW--STW--STW--STW--STW--STW--STW--STW--STW--STW--STW--STW--STW STW:start ( ReVersion ) segCnt = structure.GetCount () -- get number of segments, save in "segCnt" function FreezeLWS ( startFreeze, startLWS, inc ) freeze.UnfreezeAll () for ii = startFreeze, segCnt, inc do freeze.Freeze ( ii, true, true ) end for ii = startLWS, segCnt, inc do selection.DeselectAll () local jj = ii + inc - 1 jj = math.min ( jj, segCnt ) selection.SelectRange ( ii, jj ) structure.LocalWiggleSelected ( 3 ) end end FreezeLWS ( 2, 1, 4 ) -- statements 1-2 FreezeLWS ( 1, 2, 2 ) -- statements 4-5 FreezeLWS ( 2, 1, 2 ) -- statements 7-8 FreezeLWS ( 2, 1, 3 ) -- statements 10-11 freeze.UnfreezeAll () -- statement 12 for ii = 1, segCnt, 2 do -- statement 13 freeze.Freeze ( ii, true, true ) -- statement 13 end -- statement 13 structure.WiggleAll ( 30 ) -- statement 14 freeze.UnfreezeAll () -- statement 15 structure.ShakeSidechainsAll ( 1 ) -- statement 16 structure.WiggleAll ( 30 ) -- statement 17 STW:stop ( ReVersion )

Comments


LociOiling Lv 1

This version of Settle improves on "version a" in a couple of ways.

First, it uses a function to handle repeated freezes/local wiggles. This reduces the overall size and makes it easier to understand what's going on (hopefully).

Second, it local wiggles ranges of segments, not just single segments. This is closed to what the GUI version does, based on watching which segments pulsate as the recipe runs.

See GUI to Lua - refining Co lapse's Settle for more.

(There was a "version b", but it remains unpublished.)