Skip to content

Commit b3793aa

Browse files
committed
catch exceptions with clear_dialog
1 parent 55062de commit b3793aa

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

SerialPrograms/Source/PokemonSV/Programs/Farming/PokemonSV_ClaimMysteryGift.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*
55
*/
66

7-
#include "CommonTools/Async/InferenceRoutines.h"
7+
#include "CommonTools/Async/InferenceRoutines.h"
8+
#include "CommonFramework/Exceptions/OperationFailedException.h"
89
#include "CommonFramework/GlobalSettingsPanel.h"
910
#include "CommonFramework/Notifications/ProgramNotifications.h"
1011
#include "CommonFramework/VideoPipeline/VideoFeed.h"
@@ -148,15 +149,20 @@ void ClaimMysteryGift::claim_mystery_gift(SingleSwitchProgramEnvironment& env, P
148149
pbf_press_dpad(context, DPAD_DOWN, 20, 105);
149150
pbf_press_button(context, BUTTON_A, 20, 4 * TICKS_PER_SECOND);
150151
pbf_press_button(context, BUTTON_A, 20, 10 * TICKS_PER_SECOND);
151-
clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10, {CallbackEnum::PROMPT_DIALOG});
152+
try {
153+
clear_dialog(env.console, context, ClearDialogMode::STOP_TIMEOUT, 10, {CallbackEnum::PROMPT_DIALOG});
154+
}catch(OperationFailedException&){
155+
env.console.log("claim_mystery_gift: Failed to detect the dialog that leads to the Mystery Gift window. Reset game and re-try.", COLOR_YELLOW);
156+
reset_game(env.program_info(), env.console, context);
157+
continue;
158+
}
152159

153160
context.wait_for_all_requests();
154161
context.wait_for(Milliseconds(300));
155162
// we expect to be within Mystery Gift window, with the keyboard visible and "1" being highlighted
156-
//
157-
163+
164+
// check whether this is Switch 1 or 2.
158165
ConsoleType console_type = env.console.state().console_type();
159-
160166
if (console_type == ConsoleType::Unknown){
161167
env.console.log("Unknown Switch type. Try to detect.");
162168
console_type = detect_console_type_from_in_game(env.console, context);

0 commit comments

Comments
 (0)