josefx
josefx

Reputation: 15656

Java Scripting storing and loading state

I currently write a small game engine for 2D games in java.
As part of the engine I want to support scripts as the main way to implement in-game events.

As I want to implement a save-game function I will have to get the current state of the scripts in a format I can store in a file and load again at a later point.

Thanks
Edit: For clarity of what I want to do

  1. Game starts One or more scripts start to run in parallel
  2. Player calls save function
  3. The scripts pause
  4. The state of the scripts is stored continue or end
  5. Player calls load function
  6. the state of the scripts is loaded
  7. the scripts resume

I would like to know if there are any scripting engines for java which support pausing and storing their internal state in such a way.
(Support for the official java scripting api is not required)

Upvotes: 1

Views: 432

Answers (2)

Kylotan
Kylotan

Reputation: 18449

What you are talking about is essentially the running of coroutines, along with the ability to serialise a coroutine's state. Sadly I know little about Java or the scripting facilities available to it, but some game developers use Lua, which features coroutines, with Pluto, a serialisation library that - I'm told - allows you to save out all your individual coroutine states. Obviously this means that all the relevant state is in the coroutine and that such references that get saved out still make sense when you read them back in - this typically means access through predictable handles and ID values.

Upvotes: 1

chinmaya
chinmaya

Reputation: 609

I am not sure if this is a solution for your problem. Here are some of the scripting engine i know that work in jvm

  1. Rhino javascript engine, mozilla.org/rhino
  2. Clojure lisp engine, clojure.org
  3. groovy, groovy.codehaus.org

May be this article will help

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/

Upvotes: 0

Related Questions