Python scripting for an RPG

Started by
11 comments, last by GameDev.net 19 years, 4 months ago
I have started making a 2D Top Down RPG game engine and i would like to use scripting to control the story of the game. I chose python for the scripting because it seemed to me compared to Lua and Ruby that the syntax is much easier and the features seem vast. My problem is now that I dont understand quite how I need to go about allowing my game to be scripted. I have created a few different classes in C++ to handle the graphics, sound, logging, map loading etc. What is the best way to create the final distributable game: Is it to make the current engine into a dll and call functions from it in Python? Or to keep it as an exe and call python scripts from a new scripting class? I have currently tested SWIG to create the interface between C++ and Python and I have managed to create a test DLL from which I can call functions from. So if I do this for my game is it realistic to create a script to call the intialisation functions from my engine and run the main game loop etc. Also how can I make the *.py files into compiled python files so that when I give out the game the user cant easily change the game through the scripts. I would greatly appreciate if some one can help me understand all of this, thanks.
Advertisement
Quote:Original post by bossmonkey666
Also how can I make the *.py files into compiled python files so that when I give out the game the user cant easily change the game through the scripts.


Python automatically generates compiled output when it runs a script. You should see someScript.pyc in the same directory as someScript.py after running (directly or otherwise) that script.

I believe you should also rethink your use of scripting. If you are coding this project alone, you will get very little benefit from going through the work of integrating Python. Yes it will be quick and easy to make changes, but it's also easy to make changes in the C++ code without doing a full project rebuild. Scripting will really only benefit you if a) you have a team of people working on the game and you want to ease content creation and/or b) you want the users to be able to mod the game. If neither of those apply, it makes little since to go forward with it, IMO.
For the compiled version of your py, as stated above, just run your scripts, the compilation occurs at run time...

But I don't agree at all with the second Aldacron point.
Python is a langage that is much easier to program with, and what that's mean is that you will progress much more quickly using python...

So stick with Python, and a C++ layer for whatever need metal speed.

As for the question for the exe. You have two choices :
* Have Python embedded in your C++ exe, so provide an C++ exe. (my current choice)
* Use Python as your main language, and extend it with C++. For the distributable game, use py2exe, or create a mere exe that launch the py program using the dll or just modify the python lib in order to create your own exe !!!

I would go with the second solution ( although, or perhaps because I use the first one ).
Having C++ call the Python doesn't have any obvious advantage, and it's a nightmare to include a Python debugger in this configuration. I had some result with HAP, but HAP is unmaintained, and bugged !!!
And I don't know any other debugger for embedded python (someone ??? )

So using Python as your main program will let you use any nice python debugger you can easily find, and using VC to debug a dll called by python is easy !!

Hope it helps,
Quote:Original post by bossmonkey666
I have started making a 2D Top Down RPG game engine and i would like to use scripting to control the story of the game. I chose python for the scripting because it seemed to me compared to Lua and Ruby that the syntax is much easier and the features seem vast. My problem is now that I dont understand quite how I need to go about allowing my game to be scripted. I have created a few different classes in C++ to handle the graphics, sound, logging, map loading etc. What is the best way to create the final distributable game: Is it to make the current engine into a dll and call functions from it in Python? Or to keep it as an exe and call python scripts from a new scripting class?

I have currently tested SWIG to create the interface between C++ and Python and I have managed to create a test DLL from which I can call functions from. So if I do this for my game is it realistic to create a script to call the intialisation functions from my engine and run the main game loop etc.

Also how can I make the *.py files into compiled python files so that when I give out the game the user cant easily change the game through the scripts.

I would greatly appreciate if some one can help me understand all of this, thanks.


Like the other people said you the interpreter compiles the scripts into .pyc files but as far as I know these are pretty easy to decompile.. And I wouldn't bother with obscuring the scripts. If someone wants to change them and spoil all the fun in the game for themselves, that's their problem. Also, it will be easier to "mod" your game if you don't obscure the scripts. Your game might become more popular if it's easily moddable (I'm trying to do this in my game but alas I don't think my system is versatile and user friendly enough).

I disagree with Aldacron. I think you should use scripting, particulary in a rpg which really requires a lot of scripting (quests, items, dialogues etc.).
Ad: Ancamnia
Thanks for all of the replies.

I think I will stick with using python for my engine for various reasons: I want my game to be moddable, easily modified by me or a friend who might help with the story line, and its a good learning experience.

I think that extending Python with C++ will be easier than the other method. So I will provide my engine in a dll and call functions from it with Python (this will need some testing on my behalf but i hope it works).

With this method will the computer the game is being run on need python installed? (i really wont to ensure no further installations are needed cause then they just wont bother to play the game)

I have heard that the "python23.dll" provides the interpreter so I guess I will just try distributing it with that dll. Though if some one could please clarify this it would be great.
Quote:Original post by Anonymous Poster
But I don't agree at all with the second Aldacron point.
Python is a langage that is much easier to program with, and what that's mean is that you will progress much more quickly using python...


I don't disagree with you at all that Python is easy and productive (once you are comfortable with it). I just think it's rather pointless to use it if you are concerned about hiding your code.
Oh, I c.

My only concern is that i didnt want a file openable in text pad that would just contain most of the games stuff so any random person could change the story..I want people to have to at least go through the effort of decompiling etc to be able to change it without my concent because if they ask i would just give them all the development files to work with so they can make a new storyline altogether.

Hope that makes more sense..
I am having a problem now extending python with C++. I have succesfully created a DLL with the help of swig for the "glue code" and can import it with python and even call functions from it. I was using SDL initially to create the window for the game and the graphics (to allow porting to other OS's) but when I call the "Init" function from the DLL which should create a window it creates it then the window stops responding, it doesnt respond to any clicks and if another window goes infront of it then it wont redraw if it gets focus again.

Also when i tried to draw some text to the window it just crashed.

Any ideas?
Do you know about the Windows message pump and all that? Are the messages being handled appropriately? Not much we can say about the crash without seeing the code, although I doubt it has anything to do with the Python side.

Try perhaps calling the DLL from C++ while you debug it?
Seems like you will be doing most of the game stuff in Python so I just thought I'd point out this: http://pygame.org/. It's a python wrapper for SDL.. but if you already have an engine working in C++ then it's not really useful.
Ad: Ancamnia

This topic is closed to new replies.

Advertisement