Difference between revisions of "Guide:Bot Programming"
(16 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
− | '''Bot Programming''' has taken a unique role in [[Everybody Edits]] culture. Some despise [[Bots]] as intrusive to the game itself. Others find them quite useful. Of these supporters, divisions can still be made. Therein you find users who play [[Bot]]-Assisted Levels, users who run bot programs, and still other users who ultimately create these programs. None of these subdivisions are mutually exclusive. Therefore, you can often find players who can enjoy a fun bot and discuss how to create or practically improve the program. This guide is particularly aimed towards the '''Bot Programmers'''. This will be most beneficial to those with little to no experience. | + | '''Bot Programming''' has taken a unique role in [[Everybody Edits]] culture. Some despise [[Bots]] as intrusive to the game itself. Others find them quite useful. Of these supporters, divisions can still be made. Therein you find users who play [[Bots|Bot]]-Assisted Levels, users who run bot programs, and still other users who ultimately create these programs. None of these subdivisions are mutually exclusive. Therefore, you can often find players who can enjoy a fun bot and discuss how to create or practically improve the program. This guide is particularly aimed towards the '''Bot Programmers'''. This will be most beneficial to those with little to no experience. |
== Getting Started == | == Getting Started == | ||
Line 8: | Line 8: | ||
Communication mediums such as books and the internet provide learning experiences for all ages. If you prefer learning interactively, internet is a good choice for you. Two sites include: [https://code.org/ Code.org], which tailors to children and young adults, and [https://www.codecademy.com/ Codeacademy.com], which aims more towards the young-adult to adult range. | Communication mediums such as books and the internet provide learning experiences for all ages. If you prefer learning interactively, internet is a good choice for you. Two sites include: [https://code.org/ Code.org], which tailors to children and young adults, and [https://www.codecademy.com/ Codeacademy.com], which aims more towards the young-adult to adult range. | ||
− | However, if you would rather learn more at your own pace, there are online resources to help facilitate learning. Upon choosing this route, a programmer must also decide on a programming language. If your ultimate goal is '''Bot Programming''' and nothing beyond, C# (see-sharp) is a solid choice. However, if bots are only a side project, you could benefit from learning another language to expand your experiences. Because C# is the prevalent language in EE programming, it is the language primarily used and discussed herein. There are many online resources for learning C#, such as [http://www.tutorialspoint.com/csharp/ TutorialsPoint on csharp]. | + | However, if you would rather learn more at your own pace, there are online resources to help facilitate learning. Upon choosing this route, a programmer must also decide on a programming language. If your ultimate goal is '''Bot Programming''' and nothing beyond, C# (see-sharp) is a solid choice. However, if bots are only a side project, you could benefit from learning another language to expand your experiences. Because C# is the prevalent language in EE programming, it is the language primarily used and discussed herein. |
+ | There are many online resources for learning C#, such as [http://www.tutorialspoint.com/csharp/ TutorialsPoint on csharp]. | ||
+ | The beginner's tutorial http://www.homeandlearn.co.uk/csharp/csharp.html is highly recommended by Tomahawk. | ||
− | Completing any applicable C# tutorial in full before applying | + | Completing any applicable C# tutorial in full before applying that knowledge to EE Bot Programming is necessary if the coder does not want his or her first software to mimic a generic publically-available bot. It is stressed that the greater a programmer's proficiency at C#, the greater the number unique features he or she is able to create; a bot programmer with only elementary knowledge of the language will have difficulty creating anything great. |
===Finding an Environment=== | ===Finding an Environment=== | ||
− | This "Environment" is basically a multiple-instance text editor that helps extensively with programming. Your environment is to you as a canvas is to an artist. Into the environment you can type your hopes and dreams. If you're any good, the environment will return a functional and visually appealing system. | + | This "Environment" is basically a multiple-instance text editor that helps extensively with programming. Your environment is to you as a canvas is to an artist. Into the environment you can type your hopes and dreams. If you're any good, the environment will return a functional and visually appealing system. The most widely used program for writing and compiling bots is the [https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx Visual Studio Desktop] series. [https://msdn.microsoft.com/en-us/library/dd492171.aspx Walkthrough] A lesser-known, minimal program is [http://www.icsharpcode.net/opensource/sd/ SharpDevelop]. |
===Referencing a Language=== | ===Referencing a Language=== | ||
Line 23: | Line 25: | ||
** There will be a point where your endeavors will extend beyond the ready knowledge of the community. | ** There will be a point where your endeavors will extend beyond the ready knowledge of the community. | ||
** The Internet is full of programmers who have likely had the same errors and difficulties that you meet. | ** The Internet is full of programmers who have likely had the same errors and difficulties that you meet. | ||
− | * [http://forums.everybodyedits.com/viewforum.php?id=19 Everybody Edits Programming Forum] has a small, squabbling community who can likely help alleviate some confusion. However, | + | * [http://forums.everybodyedits.com/viewforum.php?id=19 Everybody Edits Programming Forum] has a small, squabbling community who can likely help alleviate some confusion. However, helpful answers can be difficult to obtain, and questions whose answers can be found easily elsewhere will not be received gently. |
== Programming in EE == | == Programming in EE == | ||
Line 72: | Line 74: | ||
===Common Pitfalls=== | ===Common Pitfalls=== | ||
+ | [[File:Programming-VS2010-Common-Errors.png|200px|thumb|right|Example IDE with start project]] | ||
There are some common issues to the EE community that really cannot be discovered through the usual channels, and therefore need be spoken for. | There are some common issues to the EE community that really cannot be discovered through the usual channels, and therefore need be spoken for. | ||
Line 78: | Line 81: | ||
** Have you used Thread.Sleep too much? PlayerIO passes messages to the handler on the same thread that it upkeeps connection with the server. Be sure that you create a new thread if your tasks will take too long! | ** Have you used Thread.Sleep too much? PlayerIO passes messages to the handler on the same thread that it upkeeps connection with the server. Be sure that you create a new thread if your tasks will take too long! | ||
** Are you trying to move your bot? Has the bot edit rights? Without these, EE is somewhat more strict in what movement is allowed. | ** Are you trying to move your bot? Has the bot edit rights? Without these, EE is somewhat more strict in what movement is allowed. | ||
+ | |||
+ | * Help me! Oh god, the red lines, everywhere! | ||
+ | ** Do not ask about these errors in the forums. You'll find an answer infinitely faster by simply using Google or reading and understanding what they tell you! | ||
+ | ** Check out the Error Log! It explains all of these errors. | ||
+ | *** <Character> expected -- This cannot be clearer. You wrote code that is missing a certain letter. When first starting out, this simply means add the character. When growing more complex, programs might need closer inspection to determine what level is missing the character. Alternatively, you might see "End of file expected, } found. This means you've lost that balance of { and } code blocks. Verify you didn't accidentally chop one off. | ||
+ | *** No overload for method <method> takes ## arguments -- Simply put, you need more commas. As you type the function call, a nice box (see image) pops up to explain what possible combinations of arguments you can pass. If you leave without filling the box out completely, you will get this error. Return to the line and try again! | ||
+ | *** Only assignment, call, increment, decrement, and new object expressions can be used as a statement -- You basically told the compiler to do nothing. That makes no sense, so it tells you. | ||
+ | |||
+ | |||
References: | References: |
Latest revision as of 22:38, 30 April 2024
Bot Programming has taken a unique role in Everybody Edits culture. Some despise Bots as intrusive to the game itself. Others find them quite useful. Of these supporters, divisions can still be made. Therein you find users who play Bot-Assisted Levels, users who run bot programs, and still other users who ultimately create these programs. None of these subdivisions are mutually exclusive. Therefore, you can often find players who can enjoy a fun bot and discuss how to create or practically improve the program. This guide is particularly aimed towards the Bot Programmers. This will be most beneficial to those with little to no experience.
Contents
Getting Started
You've decided to learn how to program for EE. You even had enough determination to find this guide! Much of this power of will is necessary to overcome many programming roadblocks. This will be no easy task. Before you can dive into the intricacies of writing quality programs to manipulate Everybody Edits, you first need to learn a programming language.
Learning a Language
Communication mediums such as books and the internet provide learning experiences for all ages. If you prefer learning interactively, internet is a good choice for you. Two sites include: Code.org, which tailors to children and young adults, and Codeacademy.com, which aims more towards the young-adult to adult range.
However, if you would rather learn more at your own pace, there are online resources to help facilitate learning. Upon choosing this route, a programmer must also decide on a programming language. If your ultimate goal is Bot Programming and nothing beyond, C# (see-sharp) is a solid choice. However, if bots are only a side project, you could benefit from learning another language to expand your experiences. Because C# is the prevalent language in EE programming, it is the language primarily used and discussed herein. There are many online resources for learning C#, such as TutorialsPoint on csharp. The beginner's tutorial http://www.homeandlearn.co.uk/csharp/csharp.html is highly recommended by Tomahawk.
Completing any applicable C# tutorial in full before applying that knowledge to EE Bot Programming is necessary if the coder does not want his or her first software to mimic a generic publically-available bot. It is stressed that the greater a programmer's proficiency at C#, the greater the number unique features he or she is able to create; a bot programmer with only elementary knowledge of the language will have difficulty creating anything great.
Finding an Environment
This "Environment" is basically a multiple-instance text editor that helps extensively with programming. Your environment is to you as a canvas is to an artist. Into the environment you can type your hopes and dreams. If you're any good, the environment will return a functional and visually appealing system. The most widely used program for writing and compiling bots is the Visual Studio Desktop series. Walkthrough A lesser-known, minimal program is SharpDevelop.
Referencing a Language
References are useful not only while learning a language, but even after the key points have been achieved. If you are working a tutorial and have reached an irreconcilable error, or even have questions about how to use a certain tool, you have multiple choices to pull information from.
- DotNetPerls lists multiple aspects regarding various levels of programming in C#. They also make an effort to simplify things with extensive examples, which helps with learning a new concept.
- Microsoft C# Reference covers just about everything in the language. As C#.NET is a Microsoft creation, most all the information you will need can be found here.
- Google is an invaluable tool often overlooked. If you're having trouble with syntax/compiler errors, red squiggly lines won't go away, or your window just looked at you funny, use a search engine! Take the error message, excluding line numbers and file locations, and throw it in the search bar!
- Google will help you (help yourself) much faster than the forums.
- There will be a point where your endeavors will extend beyond the ready knowledge of the community.
- The Internet is full of programmers who have likely had the same errors and difficulties that you meet.
- Everybody Edits Programming Forum has a small, squabbling community who can likely help alleviate some confusion. However, helpful answers can be difficult to obtain, and questions whose answers can be found easily elsewhere will not be received gently.
Programming in EE
If you have gained sufficient knowledge in your language (C#), you are ready to gear up to learn programming on Everybody Edits!
PlayerIO Client
EE uses a server hosting service called "PlayerIO", or more recently, "Yahoo Gamesnet." PlayerIO allows multiple EE players to join a server and swap messages with the server as a liaison. PlayerIO also defines other entry points other than the flash method. This is good news for you, because you're programming in the supported language C#(.NET). To truly create this bot, you'll need a programming library. This, namely, is "PlayerIOClient.dll". The file can be obtained through the download page here. (This link is a .zip. The .dll we need is in /DotNet/PlayerIOClient.dll.) The download also returns an example to help advance your PlayerIO knowledge. After extracting the necessary library .dll, we can add it as a reference. In each file that uses the PlayerIO library, a line must be added at the top:
using PlayerIOClient;
Client
After adding the reference, a few steps must be taken to create an operational bot. In the most basic sense, bots consist of two elements: the Client, and the Connection. The Client can be initiated in multiple ways.
- PlayerIO.QuickConnect.SimpleConnect
- PlayerIO.QuickConnect.KongregateConnect
- PlayerIO.QuickConnect.FacebookOAuthConnect
- PlayerIO.Connect
An example of a client construction:
PlayerIO.QuickConnect.SimpleConnect("everybody-edits-su9rn58o40itdbnw69plyw", "[email protected]", "password1234");
Take note that while choosing to simply require "SimpleConnect" for authentication is easier, approximately 70-80% of EE's users can use that system. [1][2]. Do you really want to ignore 20-30% of potential users?
Furthermore, if you plan on releasing your bot, be sure to make an effort to catch errors correctly. This is one example where a properly executed catch can be highly useful to the end users.
Connection
Provided a functioning, properly authenticated client, connections can be made. Multiple connections can come from one client, but only one client is allowed relation to a connection reference. Connections are the actual "joining the [world]" so-to-speak. Joining a world requires knowing the World ID. If the world is not open, the current EE Version is also necessary:
ClientReference.Multiplayer.JoinRoom("PWRoomID", null); // or
ClientReference.Multiplayer.CreateJoinRoom("PWRoomID", "Everybodyedits###", true, null, null);
To open communications, two event handlers must be added: Disconnect and MessageReceived. These can be easily generated by typing ConnectionReference.OnMessage +=
or ConnectionReference.OnDisconnect +=
and pressing TAB twice. If you use this method, it is recommended that your Connection reference have a scope higher than a function: a class property, for example. This allows the reference to be used in sending response messages to the server.
When communication directed at the server is desired, the following format is used:
ConnectionReference.Send("message type", parameters);
ConnectionReference.Send("say", "hello!"); // example
Work with EE
At this point, EE has become your oyster. You should make sure to add ConnectionReference.Send("init");
when initializing the connection, and
if (e.Type == "init") { ConnectionReference.Send("init2"); }
in the OnMessage handler.
Provided you have completed a tutorial and have a proper head on your shoulders, programming for EE should be a breeze. Multiple lists of possible EE messages exist. One popular example is user-supported here. EE Admin Processor also publishes Protocol Changelogs to the forums (and github).
Common Pitfalls
There are some common issues to the EE community that really cannot be discovered through the usual channels, and therefore need be spoken for.
- My bot connects perfectly, but when I trigger command XYZ, it disconnects! (It might even make some progress, but it still doesn't stick around!)
- Are you placing blocks in the world? If so, be sure to find an acceptable delay between messages.
System.Threading.Thread.Sleep(10);
, for example. - Have you used Thread.Sleep too much? PlayerIO passes messages to the handler on the same thread that it upkeeps connection with the server. Be sure that you create a new thread if your tasks will take too long!
- Are you trying to move your bot? Has the bot edit rights? Without these, EE is somewhat more strict in what movement is allowed.
- Are you placing blocks in the world? If so, be sure to find an acceptable delay between messages.
- Help me! Oh god, the red lines, everywhere!
- Do not ask about these errors in the forums. You'll find an answer infinitely faster by simply using Google or reading and understanding what they tell you!
- Check out the Error Log! It explains all of these errors.
- <Character> expected -- This cannot be clearer. You wrote code that is missing a certain letter. When first starting out, this simply means add the character. When growing more complex, programs might need closer inspection to determine what level is missing the character. Alternatively, you might see "End of file expected, } found. This means you've lost that balance of { and } code blocks. Verify you didn't accidentally chop one off.
- No overload for method <method> takes ## arguments -- Simply put, you need more commas. As you type the function call, a nice box (see image) pops up to explain what possible combinations of arguments you can pass. If you leave without filling the box out completely, you will get this error. Return to the line and try again!
- Only assignment, call, increment, decrement, and new object expressions can be used as a statement -- You basically told the compiler to do nothing. That makes no sense, so it tells you.