Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So, I'll be using the Java Scripting API with JavaScript to do all the scripting for the game. Now, I've read over the documentation I can't seem to figure out how I could do a one time run of some of the scripts to get all the 'different types of objects data' to be fed to Java. I'm actually not quite sure how to save all that data to Java or if I should even try saving it to Java....

QUESTION: How can I import a bunch of scripting information at run-time into my application?

share|improve this question

1 Answer 1

You can basically pass data between scripting environment and Java through the scripting API. For example,

    final ScriptEngineManager factory = new ScriptEngineManager();
    final ScriptEngine engine = factory.getEngineByName("JavaScript");

    engine.eval("greeting='Hello'");
    // Returning data from scripting environment to Java.
    // The data can also be returned from a function
    final String greeting = (String) engine.eval("greeting");
    System.out.println(greeting); //prints Hello

    //Passing data to scripting environment from Java
    engine.put("who", "foo");
    final String greetingFoo = (String) engine.eval("greeting + ', ' + who");
    System.out.println(greetingFoo); //prints Hello, foo
share|improve this answer
    
Hmm, okay. I just need to figure out how to generate all the different types of classes in java at run-time. That'll be interesting. Like I have to use all the JavaScript to create the AIs and block types and such. –  TheNickmaster21 Sep 11 '13 at 2:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.