Resolving classes in external .groovy scripts

Hey all,

I’ve added a scriptengine to my game - the idea behind this was that I wanted to add .groovy scripts inside my asset folder, and execute them inside my game engine.

The problem is that I cannot resolve my classes inside the .groovy scripts. I can still work on my own classes if I move my .groovy files inside my source.

So does anyone know of a way to add my source to the path of .groovy files placed outside my projects source?

Cheers!

well, if you’re doing scripting, then there’s really no point in adding it to your source folder OR your assets folder, as then nobody will be able to modify them (because those get compiled into a .jar).

I would suggest putting it in a different folder that can be shipped with the app…

But yeah, you’ll need the package location at the beginning of the script; that way, when it compiles at runtime, it basically puts it in that package…

Example:

package Server.Scripting

import Server.SwingLauncher
import Server.Networking.Messages.*
import com.jme3.math.*
import com.jme3.bullet.*
import com.jme3.bullet.control.RigidBodyControl

def launcher;



void meow(){
    launcher.printLn("meow");
}

Right after I load the script I set the “launcher” variable to my main class object so I can control game things from that; but you can do it a different way.

You are right, that worked (inside my asset/ folder).

My plan is to have scripts located both inside my asset folder and in my game resource folder. The scripts inside my asset folder will be core scripts, those outside will be ‘acceptable’ to modify.

The IDE still paints my groovy files red like a bolshevik parade, but they compile just fine. TY!