Python in game development?

Paul Prescod paul at prescod.net
Thu Jul 20 15:37:23 EDT 2000


Moritz Voss wrote:
> 
> Maybe I don't get the python concept. Do you link it statically? 

Yes, you link the interpreter statically and then you can pass it
strings of code to execute or arrays of already-computed byte-code.

> Now, my own language would be an assembler-style thing. The concept is as
> follows - every instruction corresponds to an index. Each of these indices,
> after compilation, are then translated, during runtime, into direct function
> addresses. So what I have is my program that consists of a huge bunch
> pointers to C functions (which can have any level of complexity). These
> would just be loaded, and called, loaded, and called. I'm not going into the
> depths of this here but passing parameters and references is not a problem.

You're going to write AI in this language? What about conditionals?
Control flow? Modularity? Exception handling? Data types?

Maybe you really need two levels of language. There is your simple
unsafe, internal-use byte-code and the player's user-level AI logic.

> I'll play around with python, but I found the way to embed it totally
> confusing. (That is, of course, because I have never worked with embedded
> languages yet). Also, I find no tutorial that clearly tells me how to change
> my C variable "X" from within my Python program "Y" that is invoked by the C
> Program.

Well Python can't directly write to pointers, which is good for you
because you want to enforce "proper" behavior (no flying through walls,
etc.) So you should start thinking a little more OO for the user-level
scripting. Let's say a handler is a function with the following
signature:

def handleAction( me, what_happened, current_time ):
	if what_happened=="hit":
 		me.shields.invoke()
		me.weapon.raise()
		me.weapon.fire()

Now each of these properties is attached to the "me" object in your C
code and each of the methods is attached to the shields and weapon
objects by the same code. The methods are *c code*. You get a callback
and update your object's internal state.
-- 
 Paul Prescod - Not encumbered by corporate consensus
"Hardly anything more unwelcome can befall a scientific writer than 
having the foundations of his edifice shaken after the work is 
finished.  I have been placed in this position by a letter from 
Mr. Bertrand Russell..." 
 - Frege, Appendix of Basic Laws of Arithmetic (of Russell's Paradox)




More information about the Python-list mailing list