Game Development Reference
In-Depth Information
for actor in actors:
if actor.is_alive():
actor.process()
The syntax is easy to follow for the most part, although Python does have certain
constructs that throw new users for a loop, like list comprehensions:
pruned_list = [x for x in actors if x.is_alive()]
This will generate a list of living actors and will run very fast (the bulk of it actually
runs in C). Another odd thing with Python that some users (including me) dislike is
that Python uses whitespace to determine scope. When you indent in Python, you
are creating a scope, and when you unindent, you step out of that scope. For an old
crusty C++ programmer like me, it can be tough to get used to. I wonder if that
'
s
how old assembly language programmers felt about the goto statement.
Overall, Python is a great language with a rich feature set. It
s been used on a number
of professional games, including Eve Online, Star Trek Bridge Commander, and the
later games in the Civilization series. We used it at Slipgate for our core gameplay
language.
'
Lua
As I said earlier, Lua is another popular scripting language that was designed from
the ground up to be an embedded language for use with native applications. It
'
s
fast, small, and an overall great language. Here
'
s some sample Lua code:
-- This is a comment in Lua
function process_actors(actors)
for index, actor in ipairs(actors) do
if actor:is_alive() then
actor.process()
end
end
end
As you can see, the syntax is relatively simple. It
s a bit more verbose than a compact
language like Python, which tends to bother some people. Lua is also much more
bare bones than Python.
The language itself has a number of very simple features and a rather sparse series of
optional libraries for math, IO, etc. Many people see this as an advantage to Lua.
Most of the code you write with your scripting language will be game or engine spe-
cific. It ' s rare that you ' ll need a network socket API or even file IO, especially since
those things can easily be exposed from the engine. A lack of these libraries means
'
 
 
 
Search WWH ::




Custom Search