mwBot
Get test api key
English zone
sección española
MW Bot Usage Calculator
Download bot
last update files

 

Handling game errors and script errors

Started by Nikolaj, 20 July 2024, 12:57

Previous topic - Next topic

Nikolaj

Handling errors in script operation

While the script is running, some errors may occur, for example, the menu has not loaded and the bot is trying to find a line, in which case the script will end with an error.
Also, the script will break if it doesn't find the line you need, for example, you want the bot to take a blue bottle from the warehouse, but it's not there, in which case the script will exit and throw an error.
For such cases, the bot provides the following event handlers
the line below will process a whole block of keystrokes and in case of an error, the bot will proceed to executing the script from line 20:. You can write the name of the event handler arbitrarily.
add_action_speak=error={"text":["^event_keypress_error"], "command":["go_to_line", 20]}the line below will process the error point by point; in this example, the error may occur on line 20, in which case the bot will proceed to executing the script from line 10.
add_action_speak=k_error1={"text":["^event_keypress_error_20"], "command": ["go_to_line", 10]}the line below will work if the condition is met and there is no error, so the bot will execute the script from line 32.
add_action_speak=k_ok={"text":["^event_keypress_ok"], "command":["go_to_line", 32]}the line below will work if the condition is met on line 29, so the bot will proceed to executing the script from line 32.
add_action_speak=k_ok1={"text":["^event_keypress_ok_29"], "command":["go_to_line", 32]}the line below allows you to ignore one-time errors in the function keypress=keyname=text
skip_keypress_error
that is, if you work with the menu, you need to write ignore the skip_keypress_error error before each key press keypress=keyname. errors will be handled using event handlers.

For greater clarity, I will publish an example of a script that will put the items you need into a warehouse.
When the script does not find the specified items in your bag, it will simply exit.
This script is universal and works the same with the English and Spanish game interface.

Below is a variable in which you specify a list of items that the bot will automatically put into the warehouse
var=items=(Goblin|Gnome|Dark elf|Dwarf)below you need to indicate the first item in your bag, which the game speaks when the menu for selecting items to put in the warehouse opens.
var=firstitem=^\d+\sArnebia
enable_restart
open_game_window
disable periodic pressing of the Escape key so that the bot does not close the menu.
disable_key_escset the target search speed, in our case it is npc (Warehouse)
search_object_timeout=0.1Below we create an event handler; if an error occurs while the script is running, the bot will execute the script from line 26.
add_action_speak=error={"text":["^event_keypress_error"], "command":["go_to_line", 26]}skip errors when pressing keypress
skip_keypress_error
enable_search_object=Almacén espaciotemporal|Ansible Space-Time Storehouse=10
keypress=enter
We are waiting for the warehouse menu to open
waitspeak=Almacén de objetos|item storagean error may occur on the line below, we have handled this above. this script can be processed point by point. if there is an error on the line below, it is better to run the script again. in the current example the script will simply exit. I didn't foresee this when I wrote this script.
keypress=s=Depositar objetos|deposit item
timewait=0.01
open the list of items that can be put into storage
keypress=enterwe wait for the game to say the name of the first item in our bag
waitspeak=%firstitem%skip the error
skip_keypress_errorWe are looking for objects whose names we indicated in the variable. if the bot does not find them, it will consider that all items have been placed in the warehouse and will complete its work. Please note that I put the digital value in parentheses; I will use this value further in the variable.
keypress=w=(\d+).*?%items%
timewait=0.01
keypress=enter
timewait=1
A field has opened for entering the number of items, I write the value using the variable that I wrote about above.
write=~~1
timewait=0.05
keypress=enter
We are waiting for a success message.
waitspeak=^Depositado|depositedwe start the cycle again and add items until we put everything that was specified in the variable at the beginning of the script.
go_to_line=10Below is line 26, which the script will go to if it receives an error.
sleep=1
break
Handling game errors

The game also has bugs, when you press keys the character does not react, and you just hear the names of the keys that you press.
to handle this, the bot has the enable_key_esc function
It is enabled by default, to work with the game menu, you need to disable it using the function
disable_key_escDon't forget to turn it on if, for example, after working with the menu your character needs to go somewhere.
The bot periodically briefly presses the Escape key. this way the game will close and the bot will restart it and continue the script.

Also sometimes the game may freeze for unknown reasons, your character may move, but when you press the "R" key, you will not get the character's health status..
There is a function to handle this error
no_regen_data=int numberif after number times it is not possible to get hp/mp indicators. then we consider that the game is frozen and end the process with the game
the default value is 5. If the bot does not receive a health value 5 times, the game will be restarted.
Other

You can report bugs found in the bot by sending the following command in the chat window:
/report your message