Programming on/with TWCore

Do you want to make bots with TWCore? Do you want to make changes to the core of TWCore? Here is the guide to get you started.

To setup your IDE with TWCore the following steps are described:

  1. Download Java
  2. Install Java
  3. Download Eclipse
  4. Install Eclipse
  5. Install Subclipse
  6. Checkout TWCore
  7. Resolve compilation problems
  8. Run TWCore
  9. Make 4 spaces on a tab
  10. Committing your changes

Note: This guide describes how to get you started using Eclipse and the Subclipse plugin which are the recommended programs to use. It's possible that you prefer a different IDE and tools however this guide doesn't guide you into setting up TWCore with these. You're welcome to add another guide though.

Do not be frightened by the length of this guide, most things will go rather quickly once you get the hang of it.


Download Java

You need Java 2 SDK for developing TWCore. We currently use Java 5 for TWCore. It's recommended that you also use Java 5 for developing so we won't get any problems with java-version-specific features/changes.

Download JDK 5.0 here: http://java.sun.com/javase/downloads/index_jdk5.jsp.
Don't choose the java version with netbeans IDE or Java EE, choose the "JDK 5.0 Update xx" download.


Install Java

Installing Java is pretty straightforward; execute the .exe file you downloaded and follow the installation instructions. If you have a newer Java version already installed, make sure this Java installation doesn't install Java into your web browsers (to avoid conflicts).


Download Eclipse

To download Eclipse go to http://www.eclipse.org/downloads/ and choose the 'Eclipse IDE for Java Developers' package.


Install Eclipse

Once downloaded, extract the 'eclipse' directory inside the zip file (suggestion: 7-zip) into C:\Program Files.
Create a shortcut at your desktop or in your start menu to C:\Program Files\eclipse\eclipse.exe .

When you start eclipse it will ask you the location of your workspace. You can choose to use the suggested default location but it's recommended to use C:\Workspaces\TWCore or an equivalent.
The first time you start eclipse it will display a welcome screen. Click on either the cross on the Welcome tab or on the silver/gold arrow in the middle/right to close it.


Install Subclipse

Subclipse is the plugin for Eclipse to work with Subversion repositories. It takes care of checking out, committing, updating, reverting code and much more. It works quite well when you know how to work with Subclipse (and Eclipse).

Follow the installation instructions of Subclipse then return here to continue the setup.


Checkout TWCore

On step 12 of the Subclipse installation instructions it said to go to the "Subclipse Repository perspective". Go there now. If you can't find it, you can go via the menu: Click on Window / Open Perspective / Other… / "SVN Repository Exploring".

Usually you may want to switch perspective using the perspective buttons at the top right of the window:

Note: You will be asked for your username/password when accessing the source repository. The username/password are the same as the credentials of your TWCore.org account. To prevent further prompts for your username and password, check the checkbox "Save Password".

Follow the following steps to checkout TWCore:

  1. In the SVN Perspective, right-click on the left area ("SVN Repository" tab), click New / Repository location…
  2. In the new window type the following URL: http://www.twcore.org/svn and press enter or click on "Finish".
  3. Once the repository has been added, click it open in the left panel by clicking on the [+] sign on the left of the URL. Open the trunk folder.
  4. Right click the twcore folder under the trunk folder and click on "Checkout…" in the menu.
  5. You should see the following window:
  6. Click on "Finish".
  7. Eclipse will now checkout TWCore from the Subversion repository.
  8. Once done, switch back to the Java perspective.


Resolve compilation problems

  • If you have the following problems then you haven't set your Java JRE:
    1. From the Java perspective, right-click the TWCore project and click on "Properties" (last option of the menu)
    2. In the new window click on "Java Build Path" in the left tree
    3. Click on the "Libraries" tab
    4. Select "JRE System Library [jdk1.5.0_12](unbound)" and click on the "Edit…" button on the right
    5. In the new window click the "Alternate JRE" radio button and click the "Installed JREs…" button on the right
    6. In the new window you'll see there is no jre1.5.0 in the list, you need to add it.
    7. Click the "Add…" button
    8. In the new window click on the "Browse…" button and navigate to the directory where you installed the JDK 5 earlier on (not the JRE directory) and click on OK.
    9. You'll notice that Eclipse has filled in most of the window. Click on OK again.
    10. In the "Installed JREs" window you'll see that jdk1.5.0_12 has been added to the list. Click on OK again.
    11. In the "JRE System Library" window select the jdk1.5.0_12 option from the list of Alternate JREs. Click on the Finish button.
    12. Click on OK.
    13. You should see only warnings (currently 648 in total) in the problems tab now:


  • If you have the following problems then you only need to refresh and clean your project:
    1. From the Java perspective, right-click the TWCore project and click on "Refresh".
    2. In the top menu, click on Project / Clean…
    3. In the new window, select "Clean all projects" and click on OK.
    4. The problems should be gone and your problems tab should display something similar to:


Run TWCore

Now that you have TWCore compiling successfully from within Eclipse, it's not that hard to get TWCore running from within Eclipse aswell.

Note: you need (access to) a subgame/biller server that run without problems for TWCore to connect to. Bots should be able to enter the server (server.ini setting) or you should have a few bot names that are on vip.txt and sysop.txt . The bots of TWCore need to be sysop since they don't return a security checksum so they can't stay connected without being logged into sysop.

You also need (access to) a mysql server for TWCore to connect to. Developers of the TW Bot Dev team can get access to the TWCore test database running on twcore.org.

  1. From within the Java perspective, lookup setup.example.cfg which is located in the src folder
  2. Select setup.example.cfg and press Ctrl+C and Ctrl+V to copy the file into the same directory.
  3. In the popup window enter the name "setup.cfg" and press OK.
  4. Double-click the new setup.cfg file and configure it. Some parameters are described in the Running On Windows guide but it should be self-explanatory.
    Notice that you have to set the "Core Location" to the bin directory within your workspace. (For example: E:\Eclipse Workspace\TWCore\bin .)
  1. Navigate to the corecfg package (under the src folder)
  2. Select all the files and press Ctrl+C and Ctrl+V
  3. Rename each file so that it doesn't have a ".example" part. (Mind that Eclipse puts "Copy of" in front of the filename.)
  4. Put your own nickname on owners.cfg and configure sql.cfg.

Now we have to set a single parameter before starting TWCore so that TWCore starts from the \bin directory.

  1. Navigate to the twcore.core package
  2. Right-click the Start.java file
  3. Click on Run As / Open Run Dialog…
  4. In the Run window double click "Java Application" from the tree left.
  5. If you see the following error then fix this error first by following the steps below:
  6. Click on the Arguments tab
  7. Under "Working directory:" select the "Other" radio button
  8. Type in: ${workspace_loc:TWCore\bin}
  9. Click the Run button

A log tab will now show where you would see that TWCore is starting up; initializing SQL connections and connecting to the subgame server. If something goes wrong it will be displayed in the log window which is usually caused by bad configuration or a problem with the SQL/subgame server.

Project compatibility error

If you have the following error in the Run dialog then follow these steps to solve this:


  1. If you are still in the Run Dialog, click the Close button to close the window
  2. From the Java perspective, right-click the TWCore project
  3. Click on "Properties" (bottom of the menu)
  4. In the Properties window, click on "Java Compiler" in the tree menu at the left
  5. Check the checkbox of "Enable project specific settings"
  6. In the fieldset "JDK Compliance" set "Compiler compliance level" to 5.0
  7. Click on OK
  8. If Eclipse asks you to rebuild the project, click on the Yes button.
  9. To reopen the Run Dialog, click the run button on the toolbar and click on "Open Run Dialog…":
  10. In the Run window, Click on Java Application / Start from the tree menu at the left

Now you have TWCore compiling and runnable from within Eclipse. You are ready to develop and test your bots!


Make 4 spaces on a tab

We recommend that for TWCore programming the 4 spaces be actual spaces.

You can set Eclipse to use the tab key to make 4 spaces rather than a tab character by doing the following;

  1. Open your TWCore project in Eclipse
  2. Go to the menu Project → Properties
  3. In the new window click on the [+] before "Java Code Style" and select "Formatter"
  4. Check the checkbox for "Enable project specific settings"
  5. Create a new profile by clicking the New… button and give it a name. (A built-in profile can't be changed.)
  6. If necessary, click on the Edit… button to edit the newly created Profile
  7. On the first tab (Indentation) set "Tab policy:" to "Spaces only"
  8. Verify that "Indentation size" and "Tab size" is set to 4
  9. Close the open dialog windows by click on the OK button


Committing your changes

See Contributing to TWCore: Committing/submitting your changes.

Attachments