Icon representing a recipe

Recipe: GetBonus 1.0

created by LociOiling

Profile


Name
GetBonus 1.0
ID
108108
Shared with
Public
Parent
None
Children
None
Created on
November 08, 2022 at 03:48 AM UTC
Updated on
November 08, 2022 at 03:52 AM UTC
Description

Display the bonus for each Objective.

Best for


Code


-- -- GetBonus - display bonuses for Objectives -- -- Gets the list of objectives, aka "filters", and displays the bonus -- for each on the screen and in the scriptlog. -- -- -- Get Bonus 1.0 - 2022/11/07 - LociOiling -- + borrow FindActiveFilter from "print protein" and modify for display -- function round ( ii ) return ii - ii % 0.001 end function FindActiveFilters () local faf = {} local fnames = filter.GetNames () print ( #fnames .. " Objectives" ) local tbonus = 0 for ii = 1, #fnames do local fenable = true if not filter.IsEnabled ( fnames [ ii ] ) then fenable = false filter.Enable ( fnames [ ii ] ) end local hasbonus = filter.HasBonus ( fnames [ ii ] ) local fscore = nil if hasbonus then bonus = filter.GetBonus ( fnames [ ii ] ) tbonus = tbonus + bonus else bonus = nil end local oot = "#" .. ii .. ": " .. fnames [ ii ] if hasbonus then oot = oot .. ", bonus = " .. round ( bonus ) else oot = oot .. ", no bonus" end print ( oot ) faf [ #faf + 1 ] = oot if not fenable then filter.Disable ( fnames [ ii ] ) end end print ( "total of individual filter bonuses = " .. round ( tbonus ) ) return #fnames, faf, tbonus end function ShowBonus ( filtc, filtz, tbonus ) if filtc > 0 then local ask = dialog.CreateDialog ( ReVersion ) ask.l15 = dialog.AddLabel ( filtc .. " objectives found." ) for ii = 1, #filtz do ask [ "f" .. ii ] = dialog.AddLabel ( filtz [ ii ] ) end ask.l17 = dialog.AddLabel ( tbonus .. " total bonus points" ) ask.OK1 = dialog.AddButton ( "OK", 1 ) ask.OK2 = dialog.AddButton ( "OK", 2 ) ask.OK3 = dialog.AddButton ( "OK", 3 ) ask.OK4 = dialog.AddButton ( "OK", 4 ) ask.OK5 = dialog.AddButton ( "OK", 5 ) ask.OK6 = dialog.AddButton ( "OK", 6 ) ask.OK7 = dialog.AddButton ( "OK", 7 ) ask.OK8 = dialog.AddButton ( "OK", 8 ) dialog.Show ( ask ) else NoBonus () end end function NoBonus ( ) local ask = dialog.CreateDialog ( ReVersion ) ask.l15 = dialog.AddLabel ( "No objectives found" ) ask.OK = dialog.AddButton ( "OK", 1 ) dialog.Show ( ask ) end function main () Recipe = "Get Bonus" Version = "1.0" ReVersion = Recipe .. " " .. Version local filtc, filtz, tbonus = FindActiveFilters () ShowBonus ( filtc, filtz, tbonus ) cleanup () end function cleanup ( errmsg ) -- cleanup v0.3 if CLEANUPENTRY ~= nil then return end CLEANUPENTRY = true print ( "---" ) local reason local start, stop, line, msg if errmsg == nil then reason = "complete" else start, stop, line, msg = errmsg:find ( ":(%d+):%s()" ) if msg ~= nil then errmsg = errmsg:sub ( msg, #errmsg ) end if errmsg:find ( "Cancelled" ) ~= nil then reason = "cancelled" else reason = "error" end end print ( ReVersion .. " " .. reason ) if reason == "error" then print ( "Unexpected error detected" ) print ( "Error line: " .. line ) print ( "Error: \"" .. errmsg .. "\"" ) end end xpcall ( main, cleanup )

Comments


LociOiling Lv 1

As suggested by jeff101, this recipe displays the bonus for every Objective (filter).

The results are shown on the screen, and are also reflected in the scriptlog.

Any disabled Objectives are temporarily enabled to get the bonus, then disabled again.

The dialog that displays the results has multiple "OK" buttons, just to make sure the dialog box is wide enough for easy reading. Otherwise, some lines may hang out over the edge of the dialog box, making them more difficult to see.