robocode-dev / tank-royale

Git repository for Robocode Tank Royale
Apache License 2.0
122 stars 23 forks source link

Add a bot log console #14

Closed beamer159 closed 2 years ago

beamer159 commented 2 years ago

When developing a bot, want to check certain values during runtime. I added some print statements to my bot's code, but when running the bot, I don't know if there is a console or similar for catching and displaying these print statements. If this feature does not exist, it would help the debugging experience. If there is currently a method to read bot print statements, please let me know.

flemming-n-larsen commented 2 years ago

Sometime later, I will add graphics debugging feature like the original Robocode. I think this feature will be even more beneficial than plain print statements. That said, we should never underestimate the value of good old logging, and this could be included as well.

For now, the best way to print out statements is to startup your bot from a command line. Here, you will see what you print out to stdout and stderr:

Java:

java -cp ../lib/* YourBot.java

C#:

dotnet run

Note that you'll need to set the environment variable SERVER_SECRET to allow your bot to join your server. You'll find the secret that your server has generated the first time you start up a battle within the file server.properties in the field named bots-secrets. Copy the value after the equal sign when you set the SERVER_SECRET. You can add this to the script used for starting your bot like this example. With Linux, you need to export the SERVER_SECRET of course.

set SERVER_SECRET=s0m3R0bOc0dEs3crEt
java -cp ../lib/* YourBot.java

How to start your bot from the command-line:

1) Start up the server, and open the dialog for selecting bots for a new battle. 2) Start your bot in from the command line. 3) Your bot will show up under "Joined bots", and you can select it the same way as when booting up bots from the bot directories. 4) Start a battle and check your console.

Of course you need to put in print or log statements to see stuff being printed out in the command line.

flemming-n-larsen commented 2 years ago

I just added a debugging article to the documentation about how to debug your bot from the command line.

beamer159 commented 2 years ago

Looks like I can get print statements with your instructions. One thing I had to change for Windows was the line setting the variable. I had to do this:

set SERVER_SECRET=yQ5eNCP46bSm5E/Uip1YrA
flemming-n-larsen commented 2 years ago

Thank you for the feedback. I will update the tutorial ASAP. 🙂

beamer159 commented 2 years ago

This should suffice for my needs. I feel fine closing this now because I just wanted to know how I could get the print statements, and your added documentation explains this. Thanks.