import com.swath.*; import com.swath.cmd.*; /** * This is my first SWATH script. * It moves your ship to a sector and lands on a planet there. * * @author Stein * @since SWATH 1.3 */ public class ExampleScript1 extends UserDefinedScript { private Parameter m_sector; private Parameter m_planet; public String getName() { // Return the name of the script return "Example Script #1"; } public String getDescription() { // Return a description of the script. // It can be an URL to a HTML page or file, // or just normal HTML text or plain text. return "This is my first SWATH script.\n"+ "It moves your ship to a sector and lands on a planet there."; } public boolean initScript() throws Exception { // Initialisation of the script is done in this method. // All parameters should be created and registered here. // If something goes wrong, return false. // Check that we are at the correct prompt if (!atPrompt(Swath.COMMAND_PROMPT)) return false; // Create the parameter 'm_sector' and set the value to the current sector. // The type will be set to INTEGER by setInteger(). // Only valid sector numbers will be accepted since setIntegerRange() is used. m_sector = new Parameter("Move to sector"); m_sector.setInteger(Swath.main.currSector()); m_sector.setIntegerRange(1, Swath.main.sectors()); m_sector.setHelpText("The sector to move to."); // Create the parameter 'm_planet' and set the type to INTEGER. // The default value will be set to 0 by setType(). m_planet = new Parameter("Land on planet"); m_planet.setType(Parameter.INTEGER); m_planet.setHelpText("The planet to land on."); // Register the 2 parameters registerParam(m_sector); registerParam(m_planet); // Some other initialisation could be done here // ... return true; } public boolean runScript() throws Exception { // Execute Move command Move.exec(m_sector.getInteger()); // Execute Land command Land.exec(m_planet.getInteger()); // End of script return true; } public void endScript(boolean finished) throws Exception { // Do some clean up here if necessary. // Remember: In Java you don't need to free any memory // since all memory is garbage collected when not used. } /** * Moves your ship to a sector and lands on a planet there. * * @param sector The sector to move to. * @param planet The planet to land on. */ public static void exec(int sector, Planet planet) throws Exception { // Create script instance ExampleScript1 script = new ExampleScript1(); // Initialise the script script.initInstance(); // Set script parameters script.m_sector.setInteger(sector); script.m_planet.setInteger(planet.id()); // Execute the script script.execInstance(); } }