Skip to content
wagyourtail edited this page Sep 6, 2020 · 8 revisions

1.0.9+

global been re-named to globalvars for compatibility with python.

1.0.4+

Globals has been changed to a class for easier interactions between js and java. examples: globalvars.putInt(a, b);, globalvars.getInt(a);

Here's a JS representation:

class globalvars {
    putInt(varname, int);
    putString(varname, string);
    putFloat(varname, float);
    putDouble(varname, double); //1.0.8+
    putBoolean(varname, bool); //1.1.7+
    
    //(this is for passing stuff like draw2d around, native "guest language" variables don't like being passed around tho...)
    putObject(varname, object) //1.1.7+ 

    getType(varname); // returns: "Int", "String", "Float", "Double", "Boolean", "Object" or null;

    // if the type is wrong these will return null;
    getInt(varname);
    getString(varname);
    getFloat(varname);
    getDouble(varname); //1.0.8+
    getBoolean(varname); //1.1.7+

    getObject(varname); //1.1.7+

    remove(varname); //1.2.0+

    getRaw(); // returns the raw HashMap<String, Object>;
}

Older

Globals is a HashMap<String, Object> passed into the javascript space as global. To add a value to it use global.set("name", value), if this throws an error you may need to convert the variable to a java variable first using Java.to(). You can later retrieve the value with global.get("name")