Icon representing a recipe

Recipe: Beginner Rebuild SCRIPT 3.01

created by LociOiling

Profile


Name
Beginner Rebuild SCRIPT 3.01
ID
102317
Shared with
Public
Parent
None
Children
None
Created on
March 28, 2017 at 04:12 AM UTC
Updated on
March 28, 2017 at 04:12 AM UTC
Description

New recipe based on work by the marquis from October, 2009. This recipe begins to extend the scope of the original Lua scripting tutorials.

Best for


Code


-- -- Automatic Rebuild script by your name here -- -- step 1 - rebuild the first 10 segments -- step 2 - add a function, use variables, use if .. then .. else, -- restore recentbest if there's a loss -- print ( "My first script!") -- -- round is a function -- -- it rounds numbers to three decimal places -- function round ( x ) return x - x % 0.001 end recentbest.Save () -- save the current pose as recentbest preScore = current.GetEnergyScore () -- preScore is a variable print ( "Score before rebuilding is " .. round ( preScore ) ) -- print rounded score selection.DeselectAll () -- deselect everything, just in case anything is selected by mistake. selection.SelectRange ( 1, 10 ) -- select segments 1 through 10 structure.RebuildSelected ( 1 ) -- rebuild the selected segments for 1 round structure.ShakeSidechainsAll ( 2 ) -- shake for 2 rounds structure.WiggleAll ( 10 ) -- wiggle it out for 10 rounds postScore = current.GetEnergyScore () -- postScore is another variable print ( "Score after rebuilding is " .. round ( postScore ) ) -- print rounded score -- -- use if-then-else to report gain or loss, reset recentbest -- if postScore > preScore then print ( "gain is " .. round ( postScore - preScore ) ) else print ( "loss is " .. round ( preScore - postScore ) .. ", resetting to recentbest pose" ) recentbest.Restore () -- reset to previous pose end

Comments