Profile
- Name
- Set Band Strength
- ID
- 103598
- Shared with
- Public
- Parent
- None
- Children
- Created on
- June 16, 2020 at 04:03 AM UTC
- Updated on
- June 16, 2020 at 04:03 AM UTC
- Description
Sets the strength of all bands to a user speified value.
Best for
Code
-- Function to draw the menu to input a strength.
function setupMenu()
menuDialog = dialog.CreateDialog("Set Band Strength")
menuDialog.strength = dialog.AddTextbox("Strength", 1)
menuDialog.set = dialog.AddButton("Set", 1)
menuDialog.cancel = dialog.AddButton("Cancel", 0)
return menuDialog
end
-- Function for showing a message if the Strength is not in the allowed range
function showOutOfRange()
rangeError = dialog.CreateDialog("Strength out of range")
rangeError.text1 = dialog.AddLabel("Band Strength must be between 0 and 10")
rangeError.OK = dialog.AddButton("OK", 1)
dialog.Show(rangeError)
end
-- Function for warning the user they did not enter a number
function showNAN()
nanError = dialog.CreateDialog("Invalid Input")
nanError.text1 = dialog.AddLabel("Value entered is not a number")
nanError.OK = dialog.AddButton("OK", 1)
dialog.Show(nanError)
end
-- Main function
function main()
-- Initialize strength
local strength = 0
-- Repeat until we break out of the loop, so that if user enters an invalid number, we can ask them to try again.
while true do
-- Show the strength menu, initialize desired length in menu to the value of length
menu = setupMenu()
-- If the user pressed the OK Button
if dialog.Show(menu) == 1 then
-- Get the length the user entered. Convert to a number
strength = tonumber(menu.strength.value)
-- Check if value cannot be converted to a number. Warn user if it cannot.
if strength == nil or strength ~= strength then
showNAN()
-- Check if number is outside range that band strength can be. Warn user if it is
elseif strength > 10 or strength < 0 then
showOutOfRange()
else
-- Loop through all the bands and set the strength to the value the user requested
for i=1, band.GetCount() do
band.SetStrength(i, strength)
end
-- Since we have now set the band strength, exit our loop
break
end
-- If menu did not return 1, user must have cancelled, so break out of loop.
else
break
end
end
end
-- Run the main function
main()
Comments