BGE Python 2.4 to 2.5 converter (in progress)


(agoose77) #1

Hello Blenderartists.
I am soon to embark on a tutorial series for Blender with my colleagues Guillame and Christian! I thought that i’d write a script converter, for those that don’t have Python skills, and want to use generic scripts in the wild. It’s working and in progress, and i’ll keep you updated here.

Blend File (please test and if something doesn’t convert, send me your test script!)
Python2.4to2.59.blend (457 KB)



(agoose77) #2

Ok, i’m nearly close to a test release


(bugs) #3

Hey It was very cool, and very useful I am very interesting by this, because I work on a game and I am start to convert all the game to blender 2.5


(agoose77) #4

Right, can someone post some old, not too complex 2.49 scripts that they KNOW are deprecated and don’t work


(kurotatsu) #5

This system would be an incredible asset for the community. An ingenious solution to a roadblock I face as well, with so much of my work wrapped up in 2.49.

Please bring this to completion, and you’ll have a friend for life.lol

This is no less than we’ve come to expect from you Agoose77, well done, truly well done.

Can’t wait for the release.

Kuro.

Edit: here’s my lifebar hud script.

gl = GameLogic
cont = gl.getCurrentController()
own = cont.owner
sceneList = GameLogic.getSceneList()
for scene in sceneList:
              
 objList = scene.objects
 
 # check object in each scene
 for obj in objList:
  
  # match player to saved player name
  if obj.name == "OB" + own['ID']:
   
   player = obj
   
   own['Text'] = player[own.prop]
   
   break
  

My script for camera collision.

g = GameLogic
c = g.getCurrentController()
o = c.getOwner()
Ray = c.getSensor("Collision")
if Ray.isPositive():    
 Collision = Ray.getHitPosition()    
 Camera = c.getSensor("CamPar").getOwner()
 Camera.setPosition(Collision)
else:    
 OrigCamera = c.getSensor("CamPos").getOwner()    
 OrigCameraLoc = OrigCamera.getPosition()    
 Camera = c.getSensor("CamPar").getOwner()    
 Camera.setPosition(OrigCameraLoc)

And if ya reaaaaalllly want ta see if it will work.lol My main player script.:eek:

#Original script by Excalaberr, additional by Kurotatsu.
import GameLogic as g
cont = g.getCurrentController()
own = cont.owner

#All input from User mouse and keyboard..
#Mouse and Ray sensors.
left = cont.sensors['kuroleft']
middle = cont.sensors['blocktap']
middleoff = cont.sensors['blockoff']
right = cont.sensors['Right']
ray = cont.sensors['ray']
#Keyboard sensors.
Wbutton = cont.sensors['Press W']
Sbutton = cont.sensors['Press S']
Abutton = cont.sensors['Press A']
Dbutton = cont.sensors['Press D']
Wbuttoff = cont.sensors['Press Woff']
Sbuttoff = cont.sensors['Press Soff']
Abuttoff = cont.sensors['Press Aoff']
Dbuttoff = cont.sensors['Press Doff']
#Attack controls(Acuators):
guard = cont.actuators['block']
idle = cont.actuators['Idle']
slash1 = cont.actuators['Attack']
slash2 = cont.actuators['ninjaslash']
slash3 = cont.actuators['jumpslash1']
throw = cont.actuators['throwshuriken']
throw2 = cont.actuators['jumpingstars']
punch = cont.actuators['punchcombo']
kick = cont.actuators['kick']
claw = cont.actuators['clawslash']
magicsmall = cont.actuators['magicsmall']
shootfireball = cont.actuators['shootfireball']
#sound(Actuators) must be set to Playstop.
jmpsnd = cont.actuators['kurojumpsound']
swdsnd = cont.actuators['swdsnd']
clawsnd = cont.actuators['clawsnd']
flamesnd = cont.actuators['flamesnd']
steelswd = cont.actuators['steelsnd']
fizzle = cont.actuators['fizzle']
#Motion(Actuators) controls:
fwd = cont.actuators['Forward']
bckwrd = cont.actuators['Backward']
leftrotate = cont.actuators['Left Turn']
rightrotate = cont.actuators['Right Turn']
leftstrafe = cont.actuators['leftsidestep']
rightstrafe = cont.actuators['rightsidestep']
stop = cont.actuators['stop']
#Property(Acuators):
manaempty = cont.actuators['manaempty']
#####################################
# This is the movement part of code.#
#####################################
#Forward
if Wbutton.positive:
 
 cont.activate(fwd)
if Wbuttoff.positive:
 
 cont.deactivate(fwd)
 cont.activate(stop)
#Backward
if Sbutton.positive:
 
 cont.activate(bckwrd)
if Sbuttoff.positive:
 
 cont.deactivate(bckwrd)
 cont.activate(stop)
#Left
if Abutton.positive and middleoff.positive:
 
 cont.activate(leftrotate)
if Abuttoff.positive:
 
 cont.deactivate(leftrotate)
 cont.activate(stop)
#Right
if Dbutton.positive and middleoff.positive:
 
 cont.activate(rightrotate)
if Dbuttoff.positive:
 
 cont.deactivate(rightrotate)
 cont.activate(stop)
####################################
#This is the Property Block of code#
####################################
 
if own['magic']<0:
 
 cont.activate(manaempty)

####################################
# This is the Attack Block of code.#
####################################
#Melee punch.
if left.positive:
 
 ray.range == own.range
 
 if own['melee']==1:
  
  cont.activate(punch)
  
  if ray.positive:
  
      obj = ray.hitObject
  
      if punch.frame >= 10:
   
   #print 'frame'
      
   if obj.has_key('enemy'):
    obj['hp'] -= 100
       
   if obj.has_key('brk'):  
    obj['brk'] += 1
  
  
#Ninjato and Polearm attack.  
if left.positive:
 
 if own['ninjato']==1:
  
  cont.activate(slash2)
  cont.activate(steelswd)
  cont.activate(jmpsnd)
  
  if ray.positive:
  
      obj = ray.hitObject
  
      if slash2.frame >= 10:
   
   #print 'frame'
      
   if obj.has_key('enemy'):
    obj['hp'] -= (own['att'])
       
   if obj.has_key('brk'):  
    obj['brk'] += 1
#Shuriken and fireball throwing while jumping.  
  
if left.positive and own['grounded']==0 :
 
 if own['ranged']==1:
  
  cont.activate(throw2)
  
if left.positive and own['grounded']==0 and own['magic']>4:
 
 if own['fireball']==1:
  
  cont.activate(magicsmall)
  cont.activate(shootfireball)
  cont.activate(throw2)
  cont.activate(flamesnd)
 
if left.positive and own['grounded']==0 and own['magic']<4:
 
 if own['fireball']==1:
  
  cont.activate(fizzle)
  
#Shuriken and fireball throwing on ground.  
if left.positive and own['grounded']==1 :
 
 if own['ranged']==1:
  
  cont.activate(throw)
  
if left.positive and own['grounded']==1 and own['magic']>4:
 
 if own['fireball']==1:
  
  cont.activate(magicsmall)
  cont.activate(shootfireball)
  cont.activate(throw)
  cont.activate(flamesnd)
  
if left.positive and own['grounded']==1 and own['magic']<4:
 
 if own['fireball']==1:
  
  cont.activate(fizzle)
  
  
#Attack jumping for all swords except ninjato.  
  
if left.positive and own['grounded']==0 :
 
 if own['slash']==1:
  
  cont.activate(slash3)
  cont.activate(swdsnd)
  
  if ray.positive:
  
      obj = ray.hitObject
  
      if slash3.frame >= 10:
   
   #print 'frame'
      
   if obj.has_key('enemy'):
    obj['hp'] -= (own['att'])
       
   if obj.has_key('brk'):  
    obj['brk'] += 1
    
    
      
#Attack on ground for all swords and katana and ax, except ninjato.
if left.positive and own['grounded']==1:
 
 if own['slash']==1:
  
  cont.activate(slash1)
  cont.activate(swdsnd)
  
  if ray.positive:
  
      obj = ray.hitObject
  
      if slash1.frame >= 10:
   
   #print 'frame'
      
   if obj.has_key('enemy'):
    obj['hp'] -= (own['att'])
       
   if obj.has_key('brk'):  
    obj['brk'] += 1
 
 
#Attack for Wolvie claws.  
if left.positive:
 
 if own['claws']==1:
  
  cont.activate(claw)
  cont.activate(clawsnd)
  
  if ray.positive:
  
      obj = ray.hitObject
  
      if claw.frame >= 10:
   
   #print 'frame'
      
   if obj.has_key('enemy'):
    obj['hp'] -= (own['att'])
       
   if obj.has_key('brk'):  
    obj['brk'] += 1
  
  
#Blocking and Stafe left and right
if middle.positive:
 
 cont.activate(guard)
 
if middle.positive and Abutton.positive:
 
 cont.activate(leftstrafe)
if middle.positive and Abuttoff.positive:
 
 cont.deactivate(leftstrafe)
 cont.activate(stop)
 
if middle.positive and Dbutton.positive:
 
 cont.activate(rightstrafe)
if middle.positive and Dbuttoff.positive:
 
 cont.deactivate(rightstrafe)
 cont.activate(stop)
  
if middleoff.positive:
  
 cont.deactivate(guard)
 cont.deactivate(leftstrafe)
 cont.deactivate(rightstrafe)
 cont.activate(stop)
#Kicking attack for ground and jumping the same. 
  
if right.positive:
 
 ray.range == 5
 
 cont.activate(kick)
 cont.activate(jmpsnd)
 
 
 if ray.positive: 
  
  obj = ray.hitObject
  
  if kick.frame >= 19:
   
   #print 'frame'
   #pay attention this one is different!!   
   if obj.has_key('enemy'):
    obj['hp'] -= (own['kick_att'])
       
   if obj.has_key('brk'):  
    obj['brk'] += 1
 

Hope this helps.:smiley:


(agoose77) #6

progress is slow due to some errors


(kurotatsu) #7

No prob, you got the skill. And errors are to be expected, so don’t lose faith.:wink: Even slow progress is progress.

Kuro.


(agoose77) #8

Request:
So, i’ve got a very basic demo for you all, and i’d like to hear what happens o.0
However, if you’re using tons of nested functions (e.g obj.setPosition(obj.getPosition()) )
i don’t know how that’ll perform :confused:


(agoose77) #9

If you’ve downloaded it, please re-download as if statements were breaking!


(agoose77) #10

Latest Version Posted.
Support for:

  • change has_key (this will also change has_key for other features :frowning:
  • getOwner() and other deprecated functions
  • addActiveActuator
  • Nested Functions

(agoose77) #11

Latest Version (.02) posted.
Support for:
Lack of spaces between operators and comparators (forgot to add the < or > symbols!)


(agoose77) #12

Fixed a kind of catastrophic error!
Let me know what bugs you receive!


(JohnnyBlack) #13

That would be just Great!


(agoose77) #14

Please try it out!


(agoose77) #15

Another little update: got a few bugfixes to post, and a slightly clearer code layout.
I’m going to work on it as best I can- there a few issues where python code is valid but irrelevant, such as hasattr and setattr because that method of accusing properties is correct, but not for gameobjects. Can anyone suggest a solution: for the moment I’m just going to notify the user, but the only method of correctin it that I can think of is to spider the Target and see if its a gameobject, but this would require a code workaround, but viable nonetheless.


(bugs) #16

I have test this, and I got an error:

Found Operator! Added spaces to relevant positions
('cam', 'GL')
Stored Modules added
Total changes made: 0
Python script error - object 'Cube', controller 'Python#CONTR#1':
Traceback (most recent call last):
  File "Converter", line 280, in &lt;module&gt;
  File "/home/bugs/Documents/Logiciels/blender/blender-2.59-linux-glibc27-i686/2.59/python/lib/python3.2/codecs.py", line 300, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe9 in position 21: invalid continuation byte

I am under Linux (Xubuntu 11.04 up to date), and there is accented character in the comments of my scripts (I am French).


(agoose77) #17

I’ve uploaded the update, so try it!
also, can you paste lines 290-310 in your script?


(bugs) #18

I have download the new blend, but the error is always at line 300.


(agoose77) #19

can i see your code? thanks!


(bugs) #20

The problem is that I use it on the script’s folder of my game, and I do not know on which file it blocks.
So if you want I can make a compress file of this folder and send you an mp with a link to download this.