Programming within a game

Xx_St0rMaF13D_xX

New Member
Joined
Dec 3, 2012
Messages
8
Reaction score
0
Hey guys, this is my first post.

My friend and I are coding a game in java(dont want to get into too much detail) one of our ideas are adding a terminal in the game and letting the player program(this is happening while playing). Is it possible to do this in java if so how would we do this and let the programming language be java. If it is not possible could someone explain how it would be done in lua and parsed into java.

Thanks:)
 
Last edited:
it should be possible in any OOP language using reflection and introspection. I don't know about java, but in Objective C you can pass the name of a class to a method and then that method can dynamically run methods of that class without the calling method knowing what the class or method would be at design time. So your user would then create their class and using an API that you provide to pass their class name to the API which would then execute their code.
 
for a basic example i can create a simple console app then allow the user to program within it and then it compiles and runs it within the programming app which is within the main application?
 
But how would you parse it in to java and how does it get compiled within the game?
Sorry if I am sounding like a noob but I am just trying to get a good understanding of how it would work

Lua is a scripting laguage.
You can use something like this http://sourceforge.net/projects/luaj/ within your program to execute lua code at runtime.

I think you can also execute javascript within java.
Have a look at the javax.script package.
 
Last edited:
Well Markus Persson (Creator of Mincraft) will be doing something like this in his next game.

Something similar yes, but not just sticking a Java terminal in and letting players compile code for fun. He's integrating it into the core gameplay as well. That's the main point here - how do you plan on making the coding essential to the gameplay, or is it just a random feature you thought would be cool?
 
Something similar yes, but not just sticking a Java terminal in and letting players compile code for fun. He's integrating it into the core gameplay as well. That's the main point here - how do you plan on making the coding essential to the gameplay, or is it just a random feature you thought would be cool?

World if Warcraft allows players to this on a limited scale. They call it macros. You can create and run them from the console and then bind the macro to a key.

Another example, which is not a game, is Microsoft Office. VBA allows users to write code to run within their application.
 
for a basic example i can create a simple console app then allow the user to program within it and then it compiles and runs it within the programming app which is within the main application?

Yes. Check out the runtime API, I know Objective C allows you create a class at runtime as well. I did this to create a datamodel based on the structure of a database table. You can even create methods.

Java can also do it, http://stackoverflow.com/questions/7608704/java-generate-class-file-at-runtime
 
nvm, read the OP properly
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X