Groovy Scripter

From ClothoWiki

Jump to: navigation, search

Groovy Scripter is the most powerful tool in Clotho. You can do ANYTHING with it! Basically, it relays the entire API to scripting using the Groovy language.

What is Groovy?

If you're unfamiliar with Groovy, it's a scripting language highly related to Java. You can instantiate Java objects, call their methods, and access their variables with essentially the same syntax as you'd use in normal Java programming. However, it's a scripting language and the syntax is a little looser than Java. Most Java statements will be interpreted the same way in Groovy, but you don't need to include semicolons (though you can) and the System.out.println(String str) method is reduced to just println(String str) or even just println str. The only major difference in syntax between the two (that I've noticed) is the use of for each loops. Where in Java you'd say:

ArrayList<Part> parts = Collector.getAll(ObjType.PART);
for(Part p : parts) {
    System.out.println(p.getName());
}

In groovy, you say "in" instead of ":" and you don't declare your variables (it won't like it if you do). So, the same block in Groovy is:

parts = Collector.getAll(ObjType.PART);
for(p in parts) {
    println p.getName()
}

How can I start using this?

Double click the tool icon in the Dashboard, then go under Help > Examples and pick one. It will put up the script. To run it, go under Run > Run groovy script or type control-R.

You can type in your own scripts and run them. You can also save your scripts and reopen them later from the File menu.

There are some additional scripts that you can copy and paste into this tool at GroovyScripts.

How can I learn what other commands I can give it?

The entire Clotho API is accessible through the Groovy Scripter, you just need to learn the API. Since writing a Groovy script is essentially identical to writing a Clotho App, I'd recommend you follow the documentation about App writing. You can also check out the javadoc for the API.