so i have a simple subroutine that works roughly like this:
on blahblah ()
would you like x or y?
does x or y
would you like to continue or stop
return result
if continue then
blahblah()
end blahblah
now what i want to do is make it so when you click stop and blahblah stops looping, the number of times you’ve chosen x or y is counted and something is done depending on the value of each. how would i do this?
global new_tea_value
global new_coffee_value
set tea_value to 0
set coffee_value to 0
myroutine(tea_value, coffee_value)
process_Tea_results(new_tea_value)
process_Coffee_results(new_coffee_value)
on myroutine(tea_value, coffee_value)
set button_pressed to button returned of (display dialog "Would you like to Tea or coffee?" buttons {"Tea", "Coffee"} default button "Tea")
if button_pressed is "Tea" then
set tea_value to tea_value + 1
else if button_pressed is "Coffee" then
set coffee_value to coffee_value + 1
end if
set button_pressed2 to button returned of (display dialog "Would you like to some more refreshments?" buttons {"Yes", "No"} default button "Yes")
if button_pressed2 is "Yes" then
myroutine(tea_value, coffee_value)
else if button_pressed2 is "No" then
set new_tea_value to tea_value
set new_coffee_value to coffee_value
end if
end myroutine
on process_Tea_results(new_tea_value)
if new_tea_value < 1 then
display dialog "You've not drunk enough Tea!"
else if new_tea_value > 5 then
display dialog "You've drunk too much Tea!"
else
display dialog "You've only had " & new_tea_value & " cups of Tea!"
end if
end process_Tea_results
on process_Coffee_results(new_coffee_value)
if new_coffee_value < 1 then
display dialog "You've not drunk enough Coffee!"
else if new_coffee_value > 3 then
display dialog "You've drunk too much Coffee!"
else
display dialog "You've only had " & new_coffee_value & " cups of Coffee!"
end if
end process_Coffee_results