Advertisement
Crashguard303

CG303 Score Part all V1.00

Jun 11th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. --[[
  2. Score Part all by Crashguard303
  3. This script calculates for each selected score part (score criteria) its score sum of all segments
  4. and their overall sum
  5. ]]--
  6. function DialogCheck()
  7.  -- create dialog containing checkboxes with names as in ScorePartNames
  8.  
  9.  local ask -- initialize table ask for dialog display and storing chekbox values
  10.  ask = dialog.CreateDialog("Get all score parts") -- windows title
  11.  ask.which = dialog.AddLabel("Calculate which score part segment sums?") -- information
  12.  
  13.  local k
  14.  for k=1,#ScorePartNames do -- by variable k, cycle through all score part names
  15.   ask[ScorePartNames[k]] = dialog.AddCheckbox(ScorePartNames[k], false)
  16.   -- for each name, create a checkbox with this variable-name and show it as text
  17.   -- default value for checkbox is false
  18.  end -- k loop
  19.  
  20.  ask.OK = dialog.AddButton("OK", 1) -- add OK button returning 1 in function if pressed
  21.  ask.Cancel = dialog.AddButton("Cancel", 0) -- add cancel button retunrning 0 in function if pressed
  22.  
  23.  return ask,dialog.Show(ask) -- return what is in table ask (containing which score parts (by names) have been selected) and flag for OK button
  24. end -- function
  25.  
  26. function ShowScores(ask)
  27.  -- for all segments, calculate all score parts selected in ask and show them
  28.  local ScoreAll=0 -- initialize variable for sum of all score-part-segment-sums
  29.  local k
  30.  for k=1,#ScorePartNames do -- by variable k, cycle through all score part names
  31.  
  32.   if ask[ScorePartNames[k]].value then -- if this score part name was checked in table ask (ask.ScorePartNames[k].value = true)
  33.    -- same as if ask[ScorePartNames[k]]["value"]
  34.    local ScorePart=0 -- initialize variable for score-part-segment-sum
  35.    local l
  36.    for l=1,NumSegs do -- by variable k, cycle through all segments
  37.     ScorePart=ScorePart+absolutebest.GetSegmentEnergySubscore(l,ScorePartNames[k])
  38.     -- add score part with name ScorePartNames[k] at segment l to score-part-segment-sum
  39.    end -- l loop
  40.  
  41.    ScoreAll=ScoreAll+ScorePart -- when all single segment-scores of one score criteria have been added, add this score-part-segment-sum value to overall sum, too
  42.    local OS=ScorePartNames[k]..": "..ScorePart -- show current score-part name and segment sum
  43.    print (OS)
  44.  
  45.   end -- if ask
  46.  
  47.  end -- k loop
  48.  
  49.  local OS="sum of all: "..ScoreAll -- when all score-part-segment-sums have been shown, show overall sum
  50.  print (OS)
  51.  
  52.  return ScoreAll -- return this value as function value
  53. end -- function
  54.  
  55. NumSegs=structure.GetCount() -- set variable NumSegs to number of all puzzle segments fetched by function
  56. ScorePartNames={"clashing";"packing";"hiding";"bonding";"backbone";"sidechain";"reference";"disulfides";"other"}
  57. -- initialize table containing all score part criteria by name
  58.  
  59. ScoreCheck={} -- initialize table containing information which score criteria should be checked, calculated and displayed
  60. local OKFlag -- initialize flag containing information if OK was pressed in score criteria selection dialog
  61.  
  62. ScoreCheck,OKFlag=DialogCheck() -- set ScoreCheck and OKFlag by calling score criteria selection dialog containing checkboxes with names as in ScorePartNames
  63.  
  64. if OKFlag>0 then -- if OK was pressed
  65.  ShowScores(ScoreCheck) -- by content of ScoreCheck, calculate scores and show them
  66. end -- if OKFlag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement