Skip to main content

Embedable scripting languages

Submitted by redwyre on

I am currently looking for a scripting language that I will embed into my next engine. I have tried lua, and while it's very easy to setup I'm not really a fan of the language. My current focus is on GameMonkey, which I've heard good things about it. Anyone tried any other languages like Python, Ruby, or any others?

Submitted by Daemin on Mon, 31/07/06 - 4:03 AMPermalink

I've been recently turned into a huge fan of Ruby. Although I don't think it's quite as easily embeddable as some other languages.

Initially I was thinking of developing a game engine in C++ and then using Ruby to script some of the game, however now I'm thinking of making the game in Ruby and only coding the high performance modules in C++. Mainly because all of the mundane file handling stuff - config files, data files, etc - can be more easily coded in Ruby, with far less code that's far more structurally sound.

I also remember seeing Python used in a game, this was in an AGDC talk in 2002 or 2003 (I can't remember), check the AGDC archive for the talk slides and links. Personally I'm not a fan of Python, something about having whitespace be a part of the language formatting.

Submitted by richard on Wed, 02/08/06 - 9:47 PMPermalink

Python's extremely simple to embed in a game. There's also games like EVE Online which are written *in* Python. The common approach is to write the game in Python first, then code any stuff that needs to be sped up in C/C++. With liberal use of third-party libraries (OpenGL, ODE, cgkit, etc) there's actually very little call for C/C++ coding in the end.

Submitted by rezn0r on Wed, 02/08/06 - 10:26 PMPermalink

I quite like Python. I find its XML stuff very handy and easy to use especially. As well as using python to bang out some quick number simulations, I've written a suite of development tools in python to handle one thing or another at work.

Yeah, the whitespace as part of the language formatting can be a drag from time to time... I've always said that if you wanted to make me cry, you'd open my python files and left justify them. :P

Scott.

Submitted by richard on Thu, 03/08/06 - 12:02 AMPermalink

LOL or try to post a snippet to most web forums :)

To counter all this whitespace-hating, I have to say I absolutely love it. Programmers indent anyway (or at least the ones that I employ ;). Why force people to type extra unnecessary stuff at the start and end of blocks?

Submitted by redwyre on Thu, 03/08/06 - 3:04 AMPermalink

Python seems like it would be rather easy to bind to code (since it is more OO out of the box than other languages such as lua, which is just tables of data). I have no problem with the whitespace, I think it's good :)

[code]and you should use
the [ code ][ /code ] tags
for code of any kind :)
[/code]

Submitted by Grover on Fri, 04/08/06 - 10:03 AMPermalink

The main problem with the whitespace in Python, is that it is scope declaration. Now if it were something less trivial, it wouldnt be suh an issue. But it means that valid incorrect code and be easily typed and there is no syntax method to determine if scopes have been incorrectly breeched.

On a small project, its a fairly trivial issue, and rarely pops up. On a large project with hundreds of python files, you go try finding a simple scope problem - errors may rarely appear but the code will be very wrong. Heres a simplistic example:

[code]
if something_happens then
Do_first_good_thing
Do_second_good thing
Do_third_good_thing
[/code]

It might seem trivial, but when these are functions, or simple math then quick visual inspection is often easily missed. I had three instances of this exact problem with a very basic little game myself and a friend made, during the week long pygame comp. And I have seen similar issues in realworld projects with python. Imho, its probably the second most critical flaw of the language. And for me, too easy to create very serious problems, and very hard to debug problems.

What I find most bizarre, is that a simple begin/end scope declaration method (either delcarations or brackets or something!) would be trivial to implement, and remove soooo many issues. I find it odd people just leave it be, and say "oh thats python..", quite odd, with such a nasty syntax flaw.

Submitted by richard on Fri, 04/08/06 - 7:29 PMPermalink

I dunno - that code looks obviously wrong to me. "Do_third_good_thing" is clearly not in the block.

Compare this to the common error in C:
[code]/* Warning: bogus C code! */
if (some condition)
if (another condition)
do_something(fancy);
else
this_sucks(badluck);[/code]

Submitted by Grover on Fri, 04/08/06 - 10:49 PMPermalink

Erm huh? Not talking about C? This is a script language why show a C example?
Its not about whether it is clearly in the block or not - because that third code section can be _anything_.
For example:
[code]
// a is a func param for instance
b = 0
c = 0
if a = 1 then
a = a + 1
b = a + 2
c = a + 3
if c = freddy then
FreddyStuff()
[/code]

See the problem? The code looks valid regardless. It will compile, and run, and just give erroneous results. And thats a very simplistic example. You put in three or four levels of indenting over say 10-20 lines and its a horrible mess in python to discern whether the code that someone wrote is intend to work that way or there is a scope issue. For script, thats insane - because thats often done by designers, whom write script by the bucket load, having a tab cause those sorts of problems is disastserous on a large project (like a game).

And like I said - its something that most languages (especially scripting ones) cater for with simple scoping rules. Whitespace for a scope rule is plain mad. Your example of C too is rarely used by any coders I know, since most places I work at require the use of the brackets as part of their code style guides. This is where script and code most often differ, since programming teams often have very strict standards that are maintained for a clean codebase. Whereas with python, even if the designers stick to pythons scoping rules, the examples Ive shown cant be determined to be correct or incorrect without asking the author. Thats plain dumb.

Submitted by richard on Fri, 04/08/06 - 11:43 PMPermalink

Sorry, but I just noticed you said "whitespace in Python ... is scope declaration". My response was addressing a different issue (that of ambiguity of blocks using optional delimiters, and style guides are a poor patch on a bad design) and I confused the discussion because of that. Again, sorry about that :)

In a nutshell: Whitespace != scope in Python

Scopes in Python are created by modules, functions and class definitions.

I'm not sure what the language is in your second example. If there's a new scope defined in the "if" statement, then sure there'd be an issue. That's simply not the case in Python though...

FWIW, between work and home projects (most of which are open-source with many varied contributors) I've got about 500,000 lines of perfectly maintainable Python code. Seems a bit silly to call these systems "scripts" really. A "script" in my book is a very short, maybe one or two screen program that is usually a throw-away hack to just get a quick job done. You can't write "scripts" in C, but you can write "code" in Python :)

Submitted by Grover on Sun, 06/08/06 - 1:35 PMPermalink

Welp, if you have 500,000 lines of python you prolly should have a look at them, and also read what scope is - file scope and local scope are probably what you should read about. Local scope is not just for classes.

[code]
# ----------------------------------------------
def AddSwappedLines(self, lines):
for l in lines:
newline = Line(l[2], l[3], l[0], l[1])
self.linecount += 1
self.vectors.append(newline)
[/code]

There are three scopes of process here, but only two real scope types - one is file scope, the other is local scope. A local scope exists within the function, and another within the for loop (or nested local scopes) - 'if' statements and such also provide local scoping - ie you can have variables and execution local to the scope of the statement.

Remove a single tab from the last line and you change the scope that line is being used in - I fail to see why this is hard to comprehend? It is suddenly outside the 'for' scope, but it is _valid_ script. Now I dont know whether you are using some new magic Python - but this is _bad_ in anyones book. And if you are using python for large projects you are in for alot of heartache.

If you are happy with whitespace controlling scope - thats cool. But please dont try to brush it off as a minor problem. This is a pretty serious issue with Python. Even with the minor amount of work and home scripting I have done with Python, I have run into this issue various times. Im utterly surprised with 500,000 lines you have never seen this issue? Maybe you havent found all the missing tabs.. I guess.

Btw I used example code before, simply for clarity. With obviously alot of Python scripting under your belt, Im surprised a bit of pseudo code wasnt easily understood. Btw the scope of execution for an 'if' or 'for' statement is _ALWAYS_ determined by whitespace. Im really puzzled why you think this is not true? Id love to hear how you are supposed to get around this problem.. Id probably recommend it, if I could make it magically disappear.

Submitted by richard on Sun, 06/08/06 - 9:57 PMPermalink

quote:There are three scopes of process here
You're referring to what is generally understood as "blocks" of code as "scopes of process" or "scopes of execution". A "scope" in a programming language is generally understood to be a namespace for variables. As you indicated, Python has a file scope, and a local scope. There's also a third builtin scope.

Python uses whitespace to define blocks where other languages may use delimiters to define blocks. It does not use whitespace to delimit scopes, except of course where a block has local scope.

Now I think I understand your position I'll stop participating in the discussion, as it's off-topic and there's no point :) You're clearly wired to need block delimiters. I, and other Python programmers, find that whitespace is enough of a block delimiter (and will react the same way to your postulation as I did - your examples of "common mistakes" are obvious mistakes to us).

quote:I used example code before, simply for clarity. With obviously alot of Python scripting under your belt, Im surprised a bit of pseudo code wasnt easily understood.
I said I didn't recognise it, not that I didn't understand it. Combined with the confusion of scope vs. block I can see why we're getting confused though :)

Submitted by Grover on Thu, 17/08/06 - 11:29 PMPermalink

You might want to look up the definition of programming scopes - seems you have a poor understanding of local scopes.
A code block is an execution scope - whether you think it is or not. Heres a nice scope article to help you out with your learning impediments:
http://en.wikipedia.org/wiki/Scope_(programming)
http://en.wikipedia.org/wiki/Local_variable

A code block IS local scope. Python uses whitespace to close and _end_ code blocks - ooh.. close and end, local SCOPE.
Oh.. that must mean that whitespace controls scoping? But if I may quote "Whitespace != scope in Python". Bzzt. Very wrong. And misleading people reading these posts.

And what is plainly bizarre, is that you consider something that visually 'looks fine syntactically' in Python, but can actually be a serious bug - missing a whitespace, can easily contribute to scoping problems that simply cant be easily vetted. Adding a simple begin/end to the code blocks would be a simple way to solve the issue, as many programming languages do, but by using whitespace, Python inherently has a syntactical flaw - regardless of whether you _think_ it has a problem, this isnt opinion related, it is a flaw.

You cant debug the problem, a compiler cannot pick the syntax error, and a script writer cant necessarily determine a fault with the script unless he/she is the author and _knows_ how the code block should operate. Hence a very critical problem with the language syntax itself.

Submitted by richard on Fri, 18/08/06 - 1:47 AMPermalink

Sorry, I know I said I wouldn't continue this discussion but I really must object. I don't believe I've stated anything misleading in my posts and I'd like for you to withdraw that accusation.

On the other hand this statement is clearly incorrect to anyone who knows Python:

quote:'if' statements and such also provide local scoping - ie you can have variables and execution local to the scope of the statement.

Python's "if" (and "else", "for", "while", "try", "except", "finally") statements do not create a new local variable scope. As I've already stated, new local scopes are only created by "def" and "class" statements.

Submitted by voxel on Sun, 08/10/06 - 2:25 PMPermalink

I pretty anti-Python for a while until I tried to create a game framework in Python for a local game jam. It's really, really easy to learn and pretty powerful. Certain language quirks like barfing on cyclical imports causes programmers to think about package + class design more carefully.

Performance is huge issue for Python - so I would only use it as a glue / game-logic language. The function-calling overhead is quite high which causes you to create funky designs trying to reduce the performance hit.

The whole "not having to declare your variables before usage" is dangerous too, but at least there is no C++ like build times (it's interpretated and very dynamic).

Posted by redwyre on

I am currently looking for a scripting language that I will embed into my next engine. I have tried lua, and while it's very easy to setup I'm not really a fan of the language. My current focus is on GameMonkey, which I've heard good things about it. Anyone tried any other languages like Python, Ruby, or any others?


Submitted by Daemin on Mon, 31/07/06 - 4:03 AMPermalink

I've been recently turned into a huge fan of Ruby. Although I don't think it's quite as easily embeddable as some other languages.

Initially I was thinking of developing a game engine in C++ and then using Ruby to script some of the game, however now I'm thinking of making the game in Ruby and only coding the high performance modules in C++. Mainly because all of the mundane file handling stuff - config files, data files, etc - can be more easily coded in Ruby, with far less code that's far more structurally sound.

I also remember seeing Python used in a game, this was in an AGDC talk in 2002 or 2003 (I can't remember), check the AGDC archive for the talk slides and links. Personally I'm not a fan of Python, something about having whitespace be a part of the language formatting.

Submitted by richard on Wed, 02/08/06 - 9:47 PMPermalink

Python's extremely simple to embed in a game. There's also games like EVE Online which are written *in* Python. The common approach is to write the game in Python first, then code any stuff that needs to be sped up in C/C++. With liberal use of third-party libraries (OpenGL, ODE, cgkit, etc) there's actually very little call for C/C++ coding in the end.

Submitted by rezn0r on Wed, 02/08/06 - 10:26 PMPermalink

I quite like Python. I find its XML stuff very handy and easy to use especially. As well as using python to bang out some quick number simulations, I've written a suite of development tools in python to handle one thing or another at work.

Yeah, the whitespace as part of the language formatting can be a drag from time to time... I've always said that if you wanted to make me cry, you'd open my python files and left justify them. :P

Scott.

Submitted by richard on Thu, 03/08/06 - 12:02 AMPermalink

LOL or try to post a snippet to most web forums :)

To counter all this whitespace-hating, I have to say I absolutely love it. Programmers indent anyway (or at least the ones that I employ ;). Why force people to type extra unnecessary stuff at the start and end of blocks?

Submitted by redwyre on Thu, 03/08/06 - 3:04 AMPermalink

Python seems like it would be rather easy to bind to code (since it is more OO out of the box than other languages such as lua, which is just tables of data). I have no problem with the whitespace, I think it's good :)

[code]and you should use
the [ code ][ /code ] tags
for code of any kind :)
[/code]

Submitted by Grover on Fri, 04/08/06 - 10:03 AMPermalink

The main problem with the whitespace in Python, is that it is scope declaration. Now if it were something less trivial, it wouldnt be suh an issue. But it means that valid incorrect code and be easily typed and there is no syntax method to determine if scopes have been incorrectly breeched.

On a small project, its a fairly trivial issue, and rarely pops up. On a large project with hundreds of python files, you go try finding a simple scope problem - errors may rarely appear but the code will be very wrong. Heres a simplistic example:

[code]
if something_happens then
Do_first_good_thing
Do_second_good thing
Do_third_good_thing
[/code]

It might seem trivial, but when these are functions, or simple math then quick visual inspection is often easily missed. I had three instances of this exact problem with a very basic little game myself and a friend made, during the week long pygame comp. And I have seen similar issues in realworld projects with python. Imho, its probably the second most critical flaw of the language. And for me, too easy to create very serious problems, and very hard to debug problems.

What I find most bizarre, is that a simple begin/end scope declaration method (either delcarations or brackets or something!) would be trivial to implement, and remove soooo many issues. I find it odd people just leave it be, and say "oh thats python..", quite odd, with such a nasty syntax flaw.

Submitted by richard on Fri, 04/08/06 - 7:29 PMPermalink

I dunno - that code looks obviously wrong to me. "Do_third_good_thing" is clearly not in the block.

Compare this to the common error in C:
[code]/* Warning: bogus C code! */
if (some condition)
if (another condition)
do_something(fancy);
else
this_sucks(badluck);[/code]

Submitted by Grover on Fri, 04/08/06 - 10:49 PMPermalink

Erm huh? Not talking about C? This is a script language why show a C example?
Its not about whether it is clearly in the block or not - because that third code section can be _anything_.
For example:
[code]
// a is a func param for instance
b = 0
c = 0
if a = 1 then
a = a + 1
b = a + 2
c = a + 3
if c = freddy then
FreddyStuff()
[/code]

See the problem? The code looks valid regardless. It will compile, and run, and just give erroneous results. And thats a very simplistic example. You put in three or four levels of indenting over say 10-20 lines and its a horrible mess in python to discern whether the code that someone wrote is intend to work that way or there is a scope issue. For script, thats insane - because thats often done by designers, whom write script by the bucket load, having a tab cause those sorts of problems is disastserous on a large project (like a game).

And like I said - its something that most languages (especially scripting ones) cater for with simple scoping rules. Whitespace for a scope rule is plain mad. Your example of C too is rarely used by any coders I know, since most places I work at require the use of the brackets as part of their code style guides. This is where script and code most often differ, since programming teams often have very strict standards that are maintained for a clean codebase. Whereas with python, even if the designers stick to pythons scoping rules, the examples Ive shown cant be determined to be correct or incorrect without asking the author. Thats plain dumb.

Submitted by richard on Fri, 04/08/06 - 11:43 PMPermalink

Sorry, but I just noticed you said "whitespace in Python ... is scope declaration". My response was addressing a different issue (that of ambiguity of blocks using optional delimiters, and style guides are a poor patch on a bad design) and I confused the discussion because of that. Again, sorry about that :)

In a nutshell: Whitespace != scope in Python

Scopes in Python are created by modules, functions and class definitions.

I'm not sure what the language is in your second example. If there's a new scope defined in the "if" statement, then sure there'd be an issue. That's simply not the case in Python though...

FWIW, between work and home projects (most of which are open-source with many varied contributors) I've got about 500,000 lines of perfectly maintainable Python code. Seems a bit silly to call these systems "scripts" really. A "script" in my book is a very short, maybe one or two screen program that is usually a throw-away hack to just get a quick job done. You can't write "scripts" in C, but you can write "code" in Python :)

Submitted by Grover on Sun, 06/08/06 - 1:35 PMPermalink

Welp, if you have 500,000 lines of python you prolly should have a look at them, and also read what scope is - file scope and local scope are probably what you should read about. Local scope is not just for classes.

[code]
# ----------------------------------------------
def AddSwappedLines(self, lines):
for l in lines:
newline = Line(l[2], l[3], l[0], l[1])
self.linecount += 1
self.vectors.append(newline)
[/code]

There are three scopes of process here, but only two real scope types - one is file scope, the other is local scope. A local scope exists within the function, and another within the for loop (or nested local scopes) - 'if' statements and such also provide local scoping - ie you can have variables and execution local to the scope of the statement.

Remove a single tab from the last line and you change the scope that line is being used in - I fail to see why this is hard to comprehend? It is suddenly outside the 'for' scope, but it is _valid_ script. Now I dont know whether you are using some new magic Python - but this is _bad_ in anyones book. And if you are using python for large projects you are in for alot of heartache.

If you are happy with whitespace controlling scope - thats cool. But please dont try to brush it off as a minor problem. This is a pretty serious issue with Python. Even with the minor amount of work and home scripting I have done with Python, I have run into this issue various times. Im utterly surprised with 500,000 lines you have never seen this issue? Maybe you havent found all the missing tabs.. I guess.

Btw I used example code before, simply for clarity. With obviously alot of Python scripting under your belt, Im surprised a bit of pseudo code wasnt easily understood. Btw the scope of execution for an 'if' or 'for' statement is _ALWAYS_ determined by whitespace. Im really puzzled why you think this is not true? Id love to hear how you are supposed to get around this problem.. Id probably recommend it, if I could make it magically disappear.

Submitted by richard on Sun, 06/08/06 - 9:57 PMPermalink

quote:There are three scopes of process here
You're referring to what is generally understood as "blocks" of code as "scopes of process" or "scopes of execution". A "scope" in a programming language is generally understood to be a namespace for variables. As you indicated, Python has a file scope, and a local scope. There's also a third builtin scope.

Python uses whitespace to define blocks where other languages may use delimiters to define blocks. It does not use whitespace to delimit scopes, except of course where a block has local scope.

Now I think I understand your position I'll stop participating in the discussion, as it's off-topic and there's no point :) You're clearly wired to need block delimiters. I, and other Python programmers, find that whitespace is enough of a block delimiter (and will react the same way to your postulation as I did - your examples of "common mistakes" are obvious mistakes to us).

quote:I used example code before, simply for clarity. With obviously alot of Python scripting under your belt, Im surprised a bit of pseudo code wasnt easily understood.
I said I didn't recognise it, not that I didn't understand it. Combined with the confusion of scope vs. block I can see why we're getting confused though :)

Submitted by Grover on Thu, 17/08/06 - 11:29 PMPermalink

You might want to look up the definition of programming scopes - seems you have a poor understanding of local scopes.
A code block is an execution scope - whether you think it is or not. Heres a nice scope article to help you out with your learning impediments:
http://en.wikipedia.org/wiki/Scope_(programming)
http://en.wikipedia.org/wiki/Local_variable

A code block IS local scope. Python uses whitespace to close and _end_ code blocks - ooh.. close and end, local SCOPE.
Oh.. that must mean that whitespace controls scoping? But if I may quote "Whitespace != scope in Python". Bzzt. Very wrong. And misleading people reading these posts.

And what is plainly bizarre, is that you consider something that visually 'looks fine syntactically' in Python, but can actually be a serious bug - missing a whitespace, can easily contribute to scoping problems that simply cant be easily vetted. Adding a simple begin/end to the code blocks would be a simple way to solve the issue, as many programming languages do, but by using whitespace, Python inherently has a syntactical flaw - regardless of whether you _think_ it has a problem, this isnt opinion related, it is a flaw.

You cant debug the problem, a compiler cannot pick the syntax error, and a script writer cant necessarily determine a fault with the script unless he/she is the author and _knows_ how the code block should operate. Hence a very critical problem with the language syntax itself.

Submitted by richard on Fri, 18/08/06 - 1:47 AMPermalink

Sorry, I know I said I wouldn't continue this discussion but I really must object. I don't believe I've stated anything misleading in my posts and I'd like for you to withdraw that accusation.

On the other hand this statement is clearly incorrect to anyone who knows Python:

quote:'if' statements and such also provide local scoping - ie you can have variables and execution local to the scope of the statement.

Python's "if" (and "else", "for", "while", "try", "except", "finally") statements do not create a new local variable scope. As I've already stated, new local scopes are only created by "def" and "class" statements.

Submitted by voxel on Sun, 08/10/06 - 2:25 PMPermalink

I pretty anti-Python for a while until I tried to create a game framework in Python for a local game jam. It's really, really easy to learn and pretty powerful. Certain language quirks like barfing on cyclical imports causes programmers to think about package + class design more carefully.

Performance is huge issue for Python - so I would only use it as a glue / game-logic language. The function-calling overhead is quite high which causes you to create funky designs trying to reduce the performance hit.

The whole "not having to declare your variables before usage" is dangerous too, but at least there is no C++ like build times (it's interpretated and very dynamic).