Skip to main content
GameDev.net gamedev.net
🔒 Locked

Scripts in games, What for?

Started by TheCompBoy Jul 28, 2011 at 12:56 PM 20 replies 4.1k views
Original Post
TheCompBoy
TheCompBoy
Hello guys!
I wonder what is scripts used for in game developement.. A friend of mine told me he used scripts in his game but i wonder like,

What benefits do you get from using scripts in your game?
What tasks can scripts do, Any examples for what i can use it?
And Which scripting language works best with Java?

Please help me get answear on theese questions or send me link to where i can find the answears,
Thanks!
Telastyn
Telastyn

What benefits do you get from using scripts in your game?


You don't need to recompile the entire game to tweak a script.
You allow modders to do more cool stuff with your game.
You provide a sandbox sort of area where people who aren't perhaps skilled enough to trust with C++ (or whatever the core of the game is done in) can still be productive.


What tasks can scripts do, Any examples for what i can use it?
[/quote]

Depends on what you expose to the scripts.
Luckless
Luckless
The basic idea of 'scripts' are to contain programming elements that may be easily changed without having to change the core program itself.

Rather than hard coding some part of the game in the complied code, such as a boss's stats and attacks, you store this part in a 'script'. When the program loads it will read this information from the script and act accordingly. If you want to change something? Just change the details of the file, but don't touch the rest of the program. Want to add more content? Just write new scripts.

The other option would be to hard code everything, which means you would have to recompile your program to make changes.
Old Username: Talroth
If your signature on a web forum takes up more space than your average post, then you are doing things wrong.
TheCompBoy
TheCompBoy
So hmm lets say i put a boss in my game.. I can with script tell the boss to shoot ever bla bla bla seconds and stuff ?

EDIT: Also which scripting language is recomended for java ?
TheCompBoy
TheCompBoy
I found this: http://www.jruby.org/

Its Ruby scripting language but its rewritter to be able to run in the java virtual machine.. I think i will try it and see if it works.
arbitus
arbitus

I found this: http://www.jruby.org/

Its Ruby scripting language but its rewritter to be able to run in the java virtual machine.. I think i will try it and see if it works.


JRuby is not necessarily a scripting language (although it can certainly be used as one), it is just a Java bytecode implementation of Ruby that runs on the JVM. Basically you are just replacing Java syntax with Ruby. Scripting is usually a runtime execution paradigm, where the scripts exist in a precompiled format, are loaded at runtime and executed on demand. Practically any language can be a scripting language as long as an interpreter exists to execute the instructions of the language on the chosen platform.

Since you mentioned the JVM, I assume you are familiar with Java? What you are looking for are scripting engines that you load in your Java program that allow you to interpret and run scripts. I am not too familiar with all of the available packages that provide scripting engines in Java, but this seems to be the Java team's official engine for scripting, using JavaScript as an example.
TheCompBoy
TheCompBoy
What i am looking for is a scripting language i can use for my game.. And so far i only found JRuby..
arbitus
arbitus

What i am looking for is a scripting language i can use for my game.. And so far i only found JRuby..


Every language is potentially a scripting language (as long as an interpreter exists for the platform), and if you read the link in my last post, you will see how to officially incorporate JavaScript scripting into your game if you are writing the game in Java. There is also Lua scripting for Java, there is Ruby (as you have already found), or you can even write your own. All of these are implemented within the ScriptEngine Java framework.

Edit: and how can I forget Jython?!
TheCompBoy
TheCompBoy
Hmm Lua realy works with java? I read in an article that i needed some library called Lualibrary or something..
geolycosa
geolycosa
Scripts are also considered "content" by most console manufacturers. Patching content is significantly easier and cheaper than patching the executable once the game is live.
Will Miller | Game Designer | Big Huge Games
TheCompBoy
TheCompBoy
How would i make eclipse support JavaScript ?? I searched on google but no answears
arbitus
arbitus

Hmm Lua realy works with java? I read in an article that i needed some library called Lualibrary or something..


Generally you need to get the JARs that contain the scripting engine implementation for the language that you choose to use, but all you have to do is drop them into your PATH and you will be able to use them via the ScriptEngine interface.
TheCompBoy
TheCompBoy
But Python would work also with Java ?
beatlefan
beatlefan

But Python would work also with Java ?


Yes, that's what Jython is for.
TheCompBoy
TheCompBoy
Oh but how would i add support in eclipse for this Jython ?
arbitus
arbitus

Oh but how would i add support in eclipse for this Jython ?


There are plugins that will allow syntax highlighting in Eclipse for various languages, but since scripts are runtime executed, there is little need for the full suite of tools offers for each language (debugger, compiler, etc.)

Instead, I suggest just getting something like Notepad++ since it already has syntax highlight support for a large variety of languages. Then you can just add your script files to eclipse as text resources. There is probably a better way, but since I use multiple IDEs and multiple languages, it works for me.
TheCompBoy
TheCompBoy
But if i add as text resources how would that work with the rest of my code?

I mean how would it know when i what to for example print something to screen or something its just text? Or would i need to add something in my code that goes into the text and reads?
arbitus
arbitus

But if i add as text resources how would that work with the rest of my code?

I mean how would it know when i what to for example print something to screen or something its just text? Or would i need to add something in my code that goes into the text and reads?


I suggest you read this link. Scripts are resources that are loaded at runtime by your game and executed using the ScriptEngine API. You will need to write the code to load and execute the scripts. Or are you looking to write the entire game using some form of scripting language?
TheCompBoy
TheCompBoy
I have a game that i made but i whant to add some features through scripting so users can change it whenever they whant to modify the game.. But i don't find any good language for it.
beatlefan
beatlefan

I have a game that i made but i whant to add some features through scripting so users can change it whenever they whant to modify the game.. But i don't find any good language for it.


Well how much would you want users to change? If it's just a few small things such as health or speed of a unit you could have a text file that has an XML-like structure where you could change the health or whatever. Then when the game run's it loads that file and sets the units stats accordingly. Doing this is simpler than adding a whole script engine and stuff, at least I would think so.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.