Icon representing a recipe

Recipe: Show Mutables V 2.0

created by gramps

Profile


Name
Show Mutables V 2.0
ID
43463
Shared with
Public
Parent
None
Children
None
Created on
July 21, 2012 at 04:12 AM UTC
Updated on
July 21, 2012 at 04:12 AM UTC
Description

lists the mutable segments in a model, a ScriptV2 adaptation of CG303 Show Mutables V1.0

Best for


Code


-- Show Mutables V 2.0 -- -- lists the mutable segments in a model -- a ScriptV2 adaptation of CG303 Show Mutables V1.0 -- -- original author CrashGuard303 -- adapted by gramps (John McLeod) -- adapted July 2012 -- this is the code example for structure.IsMutable() -- in the foldit wiki with print statements to report progress -- function returns a list of mutable segments function getMutables() local mutables={} for i=1,structure.GetCount() do if structure.IsMutable(i) then print(i, "is mutable.") mutables[#mutables+1]=i else print(i, "is not mutable.") end end return mutables end -- MAIN code print("Checking for mutable segments:") list_of_mutables = {} list_of_mutables = getMutables() print("") print("Mutating will work on these segments:") summary_line = "" if (# list_of_mutables) > 0 then -- add first mutable to list summary_line = summary_line .. list_of_mutables[1] if (# list_of_mutables) > 1 then -- check if first seg is part of a group if list_of_mutables[1] + 1 == list_of_mutables[2] then -- first group not singleton summary_line = summary_line .. ":" else -- first group is singleton summary_line = summary_line .. " " end end end colon_on = FALSE for i=2, ((# list_of_mutables) - 1) do if (list_of_mutables[i - 1 ] + 1) < list_of_mutables[i ] then -- start group summary_line = summary_line .. list_of_mutables[i] if list_of_mutables[i] + 1 == list_of_mutables[i + 1] then -- group not singleton summary_line = summary_line .. ":" else -- group is singleton summary_line = summary_line .. " " end elseif list_of_mutables[i + 1] > list_of_mutables[i] + 1 then -- end of group summary_line = summary_line .. list_of_mutables[i] .. " " end end if (# list_of_mutables) > 1 then -- add last mutable to list summary_line = summary_line .. list_of_mutables[# list_of_mutables] end print(summary_line)

Comments