Icon representing a recipe

Recipe: StepShowSubroutine 1.0.1

created by Bruno Kestemont

Profile


Name
StepShowSubroutine 1.0.1
ID
100193
Shared with
Public
Parent
None
Children
None
Created on
November 30, 2014 at 22:16 PM UTC
Updated on
November 30, 2014 at 22:16 PM UTC
Description

Keeps a pose of big steps in the undos at the end

Best for


Code


--Subroutine for recording big steps within a long lasting recipe. --by Bruno Kestemont ,30/11/2014 free use --HOW TO LOAD INTO A SCRIPT: --1 Copy these functions in the beginning if it isn't yet present in the recipe function CI(c) behavior.SetClashImportance(c) end function round(x)--cut all afer 3-rd place return x-x%0.001 end function down(x) return x-x%1 end function Score()--return score, exploration too if energy==true then return current.GetEnergyScore() else return current.GetScore() end end --2 COPY FROM HERE ... --START Movie store big steps SlotStepStart=50 SlotStep=SlotStepStart StepScore= Score() StepScore1=7000 StepScore2=9000 StepScore3=10000 StepScore4=12000 StepGain1=1000 StepGain2=500 StepGain3=200 StepGain4=100 function StoreBigStep() StepScore= Score() save.Quicksave(SlotStep) SlotStep=SlotStep+1 end function SaveBigSteps() -- in order to be able to display big steps afterwards in undos local g=Score()-StepScore local s= Score() if s >0 and ( (s <StepScore1 and g>StepGain1) or (s <StepScore2 and g>StepGain2) or (s <StepScore3 and g>StepGain3) or (s >StepScore4 and g>StepGain4)) then StoreBigStep() end end function MovieSteps() for i= SlotStepStart, SlotStep do save.Quickload(SlotStep) end --save.Quickload(3) print("See remembering of big steps in undos") end --END Movie store big steps --2 COPY ... TO HERE --3 Find the main big loop in your recipe (often in MAIN) --4 Add the function SaveBigSteps() at the end of the loop (see example bellow) --5 At the end of the recipe and/or in the error/cleaning function, include the function MovieSteps() -- like in the exemple bellow. You may end with recentbest.Restore() --HOW TO ENJOY: --At the end of your recipe, do "Undo" several times to see the show --------------------------------- --------------------------------- --Example --This only for the example on a small recipes StepGain1=5 StepGain2=3 StepGain3=1 StepGain4=1 --end settings for the example function MAIN() gen=0 ss=Score() for i = 1, 1000 do genScore=Score() gen=gen+1 print() print("Generation: "..gen..", score: "..round(Score())..", gain: "..round(Score()-ss)) structure.WiggleAll(1,true,true) SaveBigSteps() end LastWish() end function DumpErr(err) --03/02/2014 start,stop,line,msg=err:find(":(%d+):%s()") err=err:sub(msg,#err) print('---') if err:find('Cancelled')~=nil then print("User stop.") else print("unexpected error detected.") print("Error line:", line) print("Error:", err) end LastWish() end function LastWish()--03/02/2014 print("Restoring CI, best result and structures") CI(1) MovieSteps() recentbest.Restore() band.DeleteAll() end xpcall(MAIN,DumpErr)

Comments