Coron Posted February 12, 2017 Posted February 12, 2017 I'm working on a forge mod in which it is possible to compile and run (Java) scripts at runtime. It is possible to manipulate a robot, for example by making it walk to a set of coordinates or mine in a direction. The script runs on a separate thread from the game, but this causes some occasional crashes since the script may indirectly modify collections while they are being iterated. The solution to this, I think, would be that every command executed by the script would have to wait for the next game tick to execute. I know whenever the game ticks, because the robot's onEntityUpdate() is called. I'm new to Java and I've looked into synchronization, but I'm not sure what an actual implementation would look like, so I would greatly appreciate some help! Quote
Coron Posted February 12, 2017 Author Posted February 12, 2017 11 hours ago, diesieben07 said: It comes down to this: You cannot have the script run in a separate thread. You need to have the script listen for hooks like "every tick" or "every zombie tick", etc. Also, using Java for this is pretty cumbersome, since compiling stuff at runtime is tricky and not possible unless the user has the JDK installed (pretty unlikely if they aren't a developer). I suggest you use something like JavaScript, Java ships a runtime for it called Nashorn (or Rhino pre Java 8). I've managed to get it working as a temporary solution for the script to wait for the tick and then make the tick wait for the current command to execute. Obviously not a good long term solution, but fine at the moment. That's a good point, but I want to use Java (or bytecode) as I will be implementing a compiler that either compiles to Java or bytecode. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.