[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Ridiculously simple way to seperate game-object code
James Hofmann wrote:
http://people.ucsc.edu/~jhofmann/programmables.py
More "inspired by Megazeux" code.
Neat. I remember that in Megazeux the game's "objects" were actual
things with a location in the game world, to the extent that if you
wanted a "global function" you'd probably end up putting it inside a
fake wall in the corner. Programs had ways of interacting that included
traditional message-passing and physical action; eg. Robot A could
respond to being shot, and B could shoot to get A to react!
Doesn't Python have a "compile" function that turns a complex statement
into an executable code block? Something like that could be used for
if-branches and the like. So could a kludge like turning if/then
branches into GOTO statements; this could be done by some quick run-time
parsing, eg:
if health < max_health:
Cast("Heal")
else:
Attack()
becomes at run-time something like:
switch( (health < max_health) )
IF:
Cast("Heal")
ELSE:
Attack()
...where switch is basically the goto function, and takes up a cycle. I
can think of variations on this. The point is that you'd have a way to
treat the if statement as a single statement by itself, and handle the
resulting branches in seperate cycles.
I'd like to see this hooked up to some standard functions for
interacting with a game world. When I work again on my tile engine I
might include support for something like this.
As for security, you probably won't be able to make it perfect, but you
can easily provide a first line of defense by doing a TestForEvil()
function on each line before executing it, eg. "skip_line = False. for
command in FORBIDDEN_COMMANDS: if command in line_to_be_executed:
skip_line = True; print 'Hacker alert!'" You could also scan the whole
program in advance for greater efficiency, but since this code would let
a program change its own code while running (!), there's a big security
hole there.
Kris