I would like to use a class attribute in the class "associated" to my clickable object to access in each instance to the status of all instances of the class. That didn't worked, the variable was different for all the instances.
I thought it was a problem with the the python version so I put a test class in my script and it was working for it.
This is my python file (without the glue part):
- Code: Select all
from Plasma import *
from PlasmaTypes import *
from PlasmaKITypes import *
from PlasmaNetConstants import *
import xLocalization
import string
import time
actClickableObject = ptAttribActivator(1, 'Act: Clickable Object')
ObjectMsg = ptAttribString(2, 'Object String')
from TorilachaToolKit import *
# les noms des objets dans le modele blender
Cristal1 = 'Cristal1'
Cristal2 = 'Cristal2'
Cristal3 = 'Cristal3'
Cristal4 = 'Cristal4'
Cristal5 = 'Cristal5'
Foyer1 = 'Foyer1'
Foyer2 = 'Foyer2'
Foyer3 = 'Foyer3'
Foyer4 = 'Foyer4'
Foyer5 = 'Foyer5'
Braises1 = 'Braises1'
Braises2 = 'Braises2'
Braises3 = 'Braises3'
# rotation des cristaux pour les placer dans le foyer : radian, axe (x, y, z)
toRotate = ((1.5, 0, 0.0, 1, 1.5, 2), (0.0, 0, 1.5, 1, 0.0, 2),
(0.0, 0, 0.0, 1, 1.5, 2), (1.5, 0, 0.0, 1, 0.0, 2),
(3.14, 0, 1.5, 1, 0.5, 2))
# quelques constantes
zDelta = 0.1
nomCristaux = [Cristal1, Cristal2, Cristal3, Cristal4, Cristal5]
nomFoyer = [Foyer1, Foyer2, Foyer3, Foyer4, Foyer5]
nomBraises = [Braises1, Braises2, Braises3]
Bas = 0
Haut = 1
Foyer = 2
infoCristaux = {Cristal1: [Foyer1, toRotate[0]],
Cristal2: [Foyer2, toRotate[1]],
Cristal3: [Foyer3, toRotate[2]],
Cristal4: [Foyer4, toRotate[3]],
Cristal5: [Foyer5, toRotate[4]]}
#############################################################################################
# partie pour tester les attributs de classe car je commence a ne plus rien y comprendre
##############
def fonctionTest():
a = monessai()
b = monessai()
a.modifie_dic_instance('un', 1)
b.modifie_dic_instance('deux', 2)
a.modifie_dic_classe('trois', 3)
a.affiche_dic_instance()
b.affiche_dic_instance()
b.affiche_dic_classe()
a.affiche_dic_classe()
b.modifie_dic_classe('quatre', 4)
b.affiche_dic_classe()
a.affiche_dic_classe()
class monessai:
dic_classe = {'cinq' : 5}
def __init__(self):
self.dic_instance = {}
self.i = 1
def affiche_dic_instance(self):
print " ===> ",self.dic_instance
def affiche_dic_classe(self):
print " ===> ", self.__class__.dic_classe
def affiche_i(self):
print " ===> ", self.i
def modifie_dic_instance(self,cle,valeur):
self.dic_instance[cle] = valeur
def modifie_dic_classe(self, cle, valeur):
self.__class__.dic_classe[cle] = valeur
############
# fin de la zone de test
#####################################################################
class TorilachaFocus1(ptModifier,):
etatCristaux = {Cristal1: Bas, Cristal2: Bas, Cristal3: Bas, Cristal4: Bas, Cristal5: Bas}
def __init__(self):
ptModifier.__init__(self)
self.version = '1.2'
self.id = 19430003
print ('__init__%s v.%s' % (self.__class__.__name__, self.version))
# NOTE_TODO: tenir compte de variables SDL pour retrouver l'etat au chargement
# (a faire dans Torilacha.py)?
self.AgeNAme = None
self.Cristal = None
self.Foyer = None
self.posori = None
def OnFirstUpdate(self):
self.AgeName = PtGetAgeName()
print 'TorilachaFocus1.OnFirstUpdate(): AgeName=', self.AgeName
def OnServerInitComplete(self):
print ('%s: OnServerInitComplete called' % self.__class__.__name__)
# il faudrait recuperer l'objet Cristalm l'objet Foyer associe
# l'appel a IInitFire ne devrait etre fait qu'une fois
self.IInitFire()
fonctionTest() ################ uniquement pour tester si des attributs de classe peuvent fonctionner
def OnNotify(self, state, id, events):
print ('%s: OnNotify called' % self.__class__.__name__)
if ((id == actClickableObject.id) and state):
print ('Someone clicked on object %s' % ObjectMsg.value)
if (PtWasLocallyNotified(self.key)):
print 'It was you'
if ObjectMsg.value in nomCristaux:
print 'Match found! start moving ', ObjectMsg.value, ' ...'
self.IMoveCristal(ObjectMsg.value)
def IMoveCristal(self, c):
print ('%s: IMoveCristalcalled' % self.__class__.__name__)
print ('with %s' % c)
# la recuperation des objets blender devrait plutot etre faite dans OnServerInitComplete
# il faut juste trouver comment savoir a quel objet cristal correspond l'instance ...
if self.Cristal == None:
self.Cristal = PtFindSceneobject(c,self.AgeName)
if self.Cristal == None:
print 'Could not find ', c ,'!'
else:
self.posori = self.Cristal.position()
if self.Foyer == None:
self.Foyer = PtFindSceneobject(infoCristaux[c][0],self.AgeName)
if self.Foyer == None:
print 'OnServerInitComplete - could not find ', infoCristaux[c][0] ,'!'
if self.Cristal != None:
# si le cristal est en bas (position d'origine, il descend), s'il est en haut il va dans le foyer,
# s'il est dans le foyer il revient sur le support a sa position d'origine
# le foyer est impacte quand un cristal y arrive ou en repart
if self.__class__.etatCristaux[c] == Bas:
print ('switch Bas to Haut')
oldPos = self.Cristal.position()
newPos = ptPoint3(oldPos.getX(), oldPos.getY(), oldPos.getZ()+zDelta)
self.Cristal.physics.warp(newPos)
self.__class__.etatCristaux[c] = Haut
# pas besoin de mise a jour du foyer
elif self.__class__.etatCristaux[c] == Haut:
print ('switch Haut to Foyer')
# le cristal se deplace et se tourne
rot = infoCristaux[c][1]
fPos = self.Foyer.position()
cPos = self.Cristal.position()
rotObjXYZtrans(c, rot[0], rot[2], rot[4], cPos, fPos)
self.__class__.etatCristaux[c] = Foyer
# un cristal arrive dans le foyer
self.IUpdateFire()
elif self.__class__.etatCristaux[c] == Foyer:
print ('switch Foyer to Bas')
# le cristal revient a sa position d'origine (pas besoin de le retourner, l'orientation semble memorisee)
newPos = self.posori
self.Cristal.physics.warp(newPos)
self.__class__.etatCristaux[c] = Bas
# un cristal quitte le foyer
self.IUpdateFire()
def IEnableObject(self, nom):
o = PtFindSceneobject(nom, self.AgeName)
if o == None:
print 'Impossible de trouver ', nom, ' !'
else:
o.draw.enable()
o.physics.suppress(false)
def IDisableObject(self, nom):
o = PtFindSceneobject(nom, self.AgeName)
if o == None:
print 'Impossible de trouver ', nom, ' !'
else:
o.draw.disable()
o.physics.suppress(true)
def IInitFire(self):
# pas de cristaux, pas de feu
print ('%s: IInitFire' % self.__class__.__name__)
for braise in nomBraises:
self.IDisableObject(braise)
def IUpdateFire(self):
# les braises sont plus ou moins chaudes en fonction des cristaux
print ('%s: IUpdateFire' % self.__class__.__name__)
print '===', self.__class__.etatCristaux
if ((self.__class__.etatCristaux[Cristal1] == Foyer) and
(self.__class__.etatCristaux[Cristal3] == Foyer) and
(self.__class__.etatCristaux[Cristal4] == Foyer)):
print ('%s: IUpdateFire 1 3 4' % self.__class__.__name__)
self.IEnableObject(Braises3)
self.IDisableObject(Braises2)
self.IDisableObject(Braises1)
elif ((self.__class__.etatCristaux[Cristal1] == Foyer) and
((self.__class__.etatCristaux[Cristal3] == Foyer) or (self.__class__.etatCristaux[Cristal4] == Foyer))):
print ('%s: IUpdateFire 1 3 ou 4' % self.__class__.__name__)
self.IEnableObject(Braises2)
self.IDisableObject(Braises3)
self.IDisableObject(Braises1)
elif ((self.__class__.etatCristaux[Cristal3] == Foyer) and
(self.__class__.etatCristaux[Cristal4] == Foyer)):
print ('%s: IUpdateFire 3 4' % self.__class__.__name__)
self.IEnableObject(Braises2)
self.IDisableObject(Braises3)
self.IDisableObject(Braises1)
elif ((self.__class__.etatCristaux[Cristal1] == Foyer) or
(self.__class__.etatCristaux[Cristal3] == Foyer) or
(self.__class__.etatCristaux[Cristal4] == Foyer)):
print ('%s: IUpdateFire 1 ou 3 ou 4' % self.__class__.__name__)
self.IEnableObject(Braises1)
self.IDisableObject(Braises3)
self.IDisableObject(Braises2)
else :
print ('%s: IUpdateFire aucun' % self.__class__.__name__)
self.IDisableObject(Braises3)
self.IDisableObject(Braises2)
self.IDisableObject(Braises1)
def OnSDLNotify(self, VARname, SDLname, playerID, tag):
pass
def OnTimer(self, id):
pass
#--- fin de la class TorilachaFocus1
and the part of the Python.0.elf file corresponding to the "activation" of the script
- Code: Select all
....
(04/23 22:58:23) ULM: Activating book Link20
(04/23 22:58:26) __init__TorilachaBookGUI v.3.0
(04/23 22:58:26) __init__TorilachaFocus1 v.1.2
(04/23 22:58:26) __init__TorilachaFocus1 v.1.2
(04/23 22:58:26) __init__TorilachaFocus1 v.1.2
(04/23 22:58:26) __init__TorilachaFocus1 v.1.2
(04/23 22:58:26) __init__TorilachaFocus1 v.1.2
(04/23 22:58:26) __init__TorilachaBookGUI v.3.0
(04/23 22:58:26) __init__TorilachaBookGUI v.3.0
(04/23 22:58:26) __init__TorilachaFocus2 v.1.0
(04/23 22:58:26) Init1 Porte PorteGBuffet
(04/23 22:58:26) Init1 Porte PorteDBuffet
(04/23 22:58:26) __init__TorilachaFocus2 v.1.0
(04/23 22:58:26) Init1 Porte PorteGBuffet
(04/23 22:58:26) Init1 Porte PorteDBuffet
(04/23 22:58:26) Torilacha.OnFirstUpdate(): AgeName= Torilacha
(04/23 22:58:26) TorilachaFocus1.OnFirstUpdate(): AgeName= Torilacha
(04/23 22:58:26) TorilachaFocus1.OnFirstUpdate(): AgeName= Torilacha
(04/23 22:58:26) TorilachaFocus1.OnFirstUpdate(): AgeName= Torilacha
(04/23 22:58:26) TorilachaFocus1.OnFirstUpdate(): AgeName= Torilacha
(04/23 22:58:26) TorilachaFocus1.OnFirstUpdate(): AgeName= Torilacha
(04/23 22:58:26) TorilachaFocus2.OnFirstUpdate(): AgeName= Torilacha
(04/23 22:58:26) TorilachaFocus2.OnFirstUpdate(): AgeName= Torilacha
(04/23 22:58:26) TorilachaFocus1: OnServerInitComplete called
(04/23 22:58:26) TorilachaFocus1: IInitFire
(04/23 22:58:26) ===> {'un': 1}
(04/23 22:58:26) ===> {'deux': 2}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) TorilachaFocus1: OnServerInitComplete called
(04/23 22:58:26) TorilachaFocus1: IInitFire
(04/23 22:58:26) ===> {'un': 1}
(04/23 22:58:26) ===> {'deux': 2}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) TorilachaFocus1: OnServerInitComplete called
(04/23 22:58:26) TorilachaFocus1: IInitFire
(04/23 22:58:26) ===> {'un': 1}
(04/23 22:58:26) ===> {'deux': 2}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) TorilachaFocus1: OnServerInitComplete called
(04/23 22:58:26) TorilachaFocus1: IInitFire
(04/23 22:58:26) ===> {'un': 1}
(04/23 22:58:26) ===> {'deux': 2}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) TorilachaFocus1: OnServerInitComplete called
(04/23 22:58:26) TorilachaFocus1: IInitFire
(04/23 22:58:26) ===> {'un': 1}
(04/23 22:58:26) ===> {'deux': 2}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) ===> {'quatre': 4, 'trois': 3, 'cinq': 5}
(04/23 22:58:26) TorilachaFocus2: OnServerInitComplete called
(04/23 22:58:26) Init2 Porte PorteGBuffet
(04/23 22:58:26) Init2 Porte PorteDBuffet
(04/23 22:58:26) TorilachaFocus2: OnServerInitComplete called
(04/23 22:58:26) Init2 Porte PorteGBuffet
(04/23 22:58:26) Init2 Porte PorteDBuffet
(04/23 22:58:33) TorilachaFocus1: OnNotify called
(04/23 22:58:33) Someone clicked on object Cristal1
(04/23 22:58:33) It was you
(04/23 22:58:33) Match found! start moving Cristal1 ...
(04/23 22:58:33) TorilachaFocus1: IMoveCristalcalled
(04/23 22:58:33) with Cristal1
(04/23 22:58:33) switch Bas to Haut
(04/23 22:58:33) TorilachaFocus1: OnNotify called
(04/23 22:58:34) TorilachaFocus1: OnNotify called
(04/23 22:58:34) Someone clicked on object Cristal1
(04/23 22:58:34) It was you
(04/23 22:58:34) Match found! start moving Cristal1 ...
(04/23 22:58:34) TorilachaFocus1: IMoveCristalcalled
(04/23 22:58:34) with Cristal1
(04/23 22:58:34) switch Haut to Foyer
(04/23 22:58:34) rotObjXYZtrans: Cristal1 sur axe 0 de 1.5 sur axe 1 de 0.0 sur axe 2 de 1.5
(04/23 22:58:34) rotObjXYZtrans2: 0.364439964294 sur x -5.64433860779 sur y -1.37257885933 sur z
(04/23 22:58:34) TorilachaFocus1: IUpdateFire
(04/23 22:58:34) === {'Cristal2': 0, 'Cristal3': 0, 'Cristal1': 2, 'Cristal4': 0, 'Cristal5': 0}
(04/23 22:58:34) TorilachaFocus1: IUpdateFire 1 ou 3 ou 4
(04/23 22:58:34) TorilachaFocus1: OnNotify called
(04/23 22:58:36) TorilachaFocus1: OnNotify called
(04/23 22:58:36) Someone clicked on object Cristal2
(04/23 22:58:36) It was you
(04/23 22:58:36) Match found! start moving Cristal2 ...
(04/23 22:58:36) TorilachaFocus1: IMoveCristalcalled
(04/23 22:58:36) with Cristal2
(04/23 22:58:36) switch Bas to Haut
(04/23 22:58:36) TorilachaFocus1: OnNotify called
(04/23 22:58:37) TorilachaFocus1: OnNotify called
(04/23 22:58:37) Someone clicked on object Cristal2
(04/23 22:58:37) It was you
(04/23 22:58:37) Match found! start moving Cristal2 ...
(04/23 22:58:37) TorilachaFocus1: IMoveCristalcalled
(04/23 22:58:37) with Cristal2
(04/23 22:58:37) switch Haut to Foyer
(04/23 22:58:37) rotObjXYZtrans: Cristal2 sur axe 0 de 0.0 sur axe 1 de 1.5 sur axe 2 de 0.0
(04/23 22:58:37) rotObjXYZtrans2: 0.330240249634 sur x -5.36197853088 sur y -1.591142416 sur z
(04/23 22:58:37) TorilachaFocus1: IUpdateFire
(04/23 22:58:37) === {'Cristal2': 2, 'Cristal3': 0, 'Cristal1': 0, 'Cristal4': 0, 'Cristal5': 0}
(04/23 22:58:37) TorilachaFocus1: IUpdateFire aucun
(04/23 22:58:37) TorilachaFocus1: OnNotify called
I was expecting
- Code: Select all
(04/23 22:58:37) === {'Cristal2': 2, 'Cristal3': 0, 'Cristal1': 2, 'Cristal4': 0, 'Cristal5': 0}
- Code: Select all
(04/23 22:58:37) === {'Cristal2': 2, 'Cristal3': 0, 'Cristal1': 0, 'Cristal4': 0, 'Cristal5': 0}
What's the problem with my etatCristaux class attribute ?
Thanks.