Scripting languages in games - question

Started by
14 comments, last by Ekim_Gram 20 years, 2 months ago
quote:Original post by Ekim_Gram
Alright, I''m thinking Python for a scripting language. Now, my next question is, since it''ll be used to hold variables of different objects of my game(s), how do I incorperate it with C/C++?
Extending and Embedding Python
Advertisement
quote:Original post by Cor
Realistically to a designer if you construct things well, there is little difference between writing in lua and writing in c/c++.


Counter-examples:

1) Iterating over a structure is far easier in Lua:
> table = { sword=10, axe=15, mace=20 }> for key,value in table do print(key,value) end mace    20 sword   10 axe     15  


2) Returning multiple values is simpler:
> function getposition() return xpos, ypos end> x, y = getposition()> print(x)1> print(y)2  


3) Simulating multithreading with coroutines for ongoing events
> function talk()>> print("Good to meet you.")>> coroutine.yield()>> print("Hello again.")>> end> co = coroutine.create(talk)> coroutine.resume(co)Good to meet you.> coroutine.resume(co)Hello again.  


All the above are possible with C++. But even with Boost, STL, and friends, you're not gonna achieve any of the above as cleanly or as quickly.

For what it's worth, I could do all the above in Python too, with next to no change in the syntax; I just chose Lua as that seems to be the language discussed in this thread.

quote:Recompiling a few thousand lines of c/c++ takes just a few seconds


With Python or Lua embedded carefully enough, you could even make the changes without restarting the program, never mind recompiling. See your changes in real-time. View complex expressions from the in-game console.

quote:My opinion is that many times, even myself included it's the programmers who want to add scripting because it is an interesting topic, but in just about every case I've looked at, things could have been done pretty much exactly the same, except faster using native code.


This much is probably true. You really need to have worked with other languages for a while before you can truly appreciate the benefits they can bring. Only then will you be likely to get the full benefit from using one.


Ekim_Gram; take a look at the FAQ in the Scripting Languages forum.

[ MSVC Fixes | STL Docs | SDL | Game AI | Sockets | C++ Faq Lite | Boost
Asking Questions | Organising code files | My stuff | Tiny XML | STLPort]

[edited by - Kylotan on February 21, 2004 9:01:30 AM]
quote:Original post by Oluseyi
quote:Original post by mattnewport
C and C++ were designed for maximum runtime performance rather than maximum ease of use or maximum programmer productivity.
While I agree with the rest of your post in general, this is completely false. C and C++ were designed to increase programmer productivity, given the tools programmers used and the problems they needed to solve at that time.

My original statement was probably a bit of an over generalisation but if you read ''The Design and Evolution of C++'' by Bjarne Stroustrup he is very clear that certain design decisions in C++ were taken because performance was considered more important than ease of use or programmer productivity. Stroustrup felt (probably correctly) that C programmers would never accept C++ if it imposed a significant performance penalty. There were other languages around at the time that influenced the design of C++ (Smalltalk for example) that were not widely adopted because their performance was seen as too poor for many applications. Certainly C was a step up from assembly language but higher level languages have failed to replace C and C++ in many domains largely because of performance concerns. Whether those concerns are justified in many cases is another question...

Game Programming Blog: www.mattnewport.com/blog

quote:Original post by Cor
I was originally going to use lua scripts to control various game aspects but at some point I realized that for me, it made no sense at all. And at this point I don''t really see who it would make sense for.[...]
Consier RTS games, where scripting is quite common. A semi-recent example would be warcraft 3. When you''re making a level, you can create a script to make the level do more interesting things, such as make a lever open a door, or spawn 50 monsters, or set a variable such that you have to hit a specific lever next to open a combination lock of some kind. You can use the script to make monsters move a certain way, attack certain units before others, etc.

The custom maps not made by blizzard are what kept the game alive for me as long as it was. Without them, I wouldn''t have bought the game at all. Not only do the scripts allow such customization, they also allow it safely. If you were to replace the script with SDK source like many FPS have, and just have the dll attached to the map, then you have security problems since the maps are automatically downloaded by users if they try to join a game with a map they don''t have.

It also makes sense for RPGs, where you want the same kind of flexability (in developers'' levels or those created by fans).

"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk

I think Python is a hell of a language, and since it ties so nicely into C/C++ it makes it that much more sweet.

One thing to remember as well, once you start down the path of scripting and embedding you can start to appreciate how quickly you can prototype things out in a language such as Python ( like Kylotan''s examples above as a real minimal example of how concise the code can be ).

I haven''t used LUA really, since Python has fulfilled 100% of my needs.. but it seems decent from what I''ve read-up on it.

.z
quote:Original post by Oluseyi
At the time the de facto industry standard was C (it should still be, to a large extent, IMO)


I agree with your statement concerning C, even though I am one of the Lisp proponents.

Any language can interface to a library or DLL if it has a C API. C is the common denominator. Trying to interface to libraries that export a C++ API is just a pain. And I''m not just taking the Lisp viewpoint here. Delphi<->C++, Java<->C++ etc. it''s a pain. All libraries should have, at a minimum, a C API.

This topic is closed to new replies.

Advertisement