Crystal Space
Welcome, Guest. Please login or register.
April 23, 2014, 09:53:26 pm

Login with username, password and session length
Search:     Advanced search
8990 Posts in 2037 Topics by 7618 Members
Latest Member: Tymqwaro
* Home Help Search Login Register
+  Crystal Space
|-+  Miscellaneous
| |-+  Article/Tutorial Discussion
| | |-+  Writing Python tutorial... problem
« previous next »
Pages: [1] Print
Author Topic: Writing Python tutorial... problem  (Read 5741 times)
Ruel Haldi
Newbie
*
Posts: 18


View Profile Email
« on: April 20, 2006, 02:51:11 am »

I'm trying to write a tutorial for newcomers. It's also for my own good, since I get good experience out of it. My goal is to translate several of the tutorial programs that come with CS into Python scripts. Other people would probably be more qualified, but it needs to be done, so I'll do my best. The tutorial would be a line-by-line comparison between the two languages so that new users can see how to build their own programs in Python.

Right now, I'm working on a translation of the isotest program. I've gotten pretty far, but I've run into an odd snag. Specifically, it appears that you can't create a light in Python. Here's the chunk of code:

Code:
try:
  actor_light=self.engine.CreateLight(0, csVector3(-3,5,0), 5, csColor(1,1,1))
except: 
  msg=traceback.format_exc()
  csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,"crystalspace.application.isotest",msg)

NOTE: for new Python users. It took me a long time to figure out a proper debug method in CS. I'm accustomed to just printing and reading error messages in the terminal window. If you haven't found your own method, the try/except clause above works quite well.

I hope someone can help me. When I run the program, it fails to create the light. It also gives a very odd traceback message:
Quote
File "C:\CS\isotest.py", line 143, in LoadMap
   actor_light=self.engine.CreateLight(0,csVector3(-3,5,0),5,csColor(1,1,1))
File "C:\CS\cspace.py", line 4269, in CreateLight
   def CreateLight(*args): return _cspace.iEngine_CreateLight(*args)
NotImplementedError: No matching function for overloaded 'iEngine_CreateLight'

As said above, I'm probably not the best man for the job, because I don't know what to do about this. It sounds like cspace.py doesn't have a proper function for iEngine.CreateLight.  However cspace.py was built by SWIG wasn't it? Any ideas?
Logged
Ruel Haldi
Newbie
*
Posts: 18


View Profile Email
« Reply #1 on: April 20, 2006, 03:35:10 pm »

I'm still stuck on the last problem, but I kept going so I could find any more issues.

Code:
self.spstate = SCF_QUERY_INTERFACE (self.actor.GetMeshObject (), iGeneralMeshState)
self.animcontrol = SCF_QUERY_INTERFACE (self.spstate.GetAnimationControl (), iGenMeshSkeletonControlState)

The first line works fine, the second generates this Traceback:

Quote
File "C:\CS\isotest.py", line 190 in CreateActor
  self.animcontrol=SCF_QUERY_INTERFACE (self.spstate.GetAnimationControl (), iGenMeshSkeletonControlState)
NameError: global name 'iGenMeshSkeletonControlState' is not defined

Sounds like Python doesn't recognize the keyword for the 'iGenMeshSkeletonControlState' structure. Not sure how to approach this problem. I assume the isotest.cpp include for gmeshskel.h isn't loaded by cspace.pyd.  Or it wasn't SWIGed properly. Any ideas on what to try next?

You know, it'd be nice if we had a forum dedicated to Python users and issues. Maybe call it CrystalPy?  Hehe...
Logged
Ruel Haldi
Newbie
*
Posts: 18


View Profile Email
« Reply #2 on: April 20, 2006, 07:55:42 pm »

All right!  I figured out and fixed the first problem. Since I've been copying the code from isotest.cpp to build isotest.py (so I can have a comparison), I used the line "actor_light=self.engine.CreateLight(0, csVector3(-3,5,0), 5, csColor(1,1,1))" as it was written in C.  However, this doesn't work in Python. The first field MUST be given a name even if the name is an empty string.

So, "actor_light=self.engine.CreateLight("", csVector3(-3,5,0), 5, csColor(1,1,1))" works.

Now, if I can just figure out the second issue listed above with iGenMeshSkeletonControlState
Logged
Ruel Haldi
Newbie
*
Posts: 18


View Profile Email
« Reply #3 on: May 02, 2006, 01:35:55 am »

Well... here it is. I still haven't figured out the iGenMeshSkeletonControlState, so if anyone wants to correct that, please do!  Likewise, I haven't figured out how to use the shift keys in Python, because the CrystalSpace constants for the shift keys are undefined.

My purpose here was to take the isotest demo script included with CrystalSpace and rewrite it in Python. They are presented side by side, so the reader can compare the C code to the Python code.

Suggestions for better presentation (I'd love to color it like an IDE) or fixes are appreciated.

Here's the link. Should I upload this somewhere? Maybe the CrystalSpace Wiki I've heard about (but can't find)?

Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 6.225 seconds with 17 queries.