[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16347] trunk/blender/source/gameengine: BGE Py api, deleting properties didnt raise an error when the property wasnt there.

Campbell Barton ideasman42 at gmail.com
Wed Sep 3 08:43:07 CEST 2008


Revision: 16347
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16347
Author:   campbellbarton
Date:     2008-09-03 08:43:07 +0200 (Wed, 03 Sep 2008)

Log Message:
-----------
BGE Py api, deleting properties didnt raise an error when the property wasnt there. also added some exception messages and renamed joystick getConnected() to isConnected()

Modified Paths:
--------------
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
    trunk/blender/source/gameengine/Expressions/Value.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2008-09-03 03:37:47 UTC (rev 16346)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2008-09-03 06:43:07 UTC (rev 16347)
@@ -119,6 +119,7 @@
 
 int PyObjectPlus::_delattr(const STR_String& attr)
 {
+	PyErr_SetString(PyExc_AttributeError, "attribute cant be deleted");
 	return 1;
 }
 
@@ -126,7 +127,8 @@
 {
 	//return PyObject::_setattr(attr,value);
 	//cerr << "Unknown attribute" << endl;
-  return 1;
+	PyErr_SetString(PyExc_AttributeError, "attribute cant be set");
+	return 1;
 }
 
 /*------------------------------

Modified: trunk/blender/source/gameengine/Expressions/Value.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/Value.cpp	2008-09-03 03:37:47 UTC (rev 16346)
+++ trunk/blender/source/gameengine/Expressions/Value.cpp	2008-09-03 06:43:07 UTC (rev 16347)
@@ -391,16 +391,23 @@
 bool CValue::RemoveProperty(const STR_String & inName)
 {
 	// Check if there are properties at all which can be removed
-	if (m_pNamedPropertyArray == NULL)
-		return false;
-
-	CValue* val = GetProperty(inName);
-	if (NULL != val) 
-	{
-		val->Release();
-		m_pNamedPropertyArray->erase(inName);
-		return true;
-	}
+	if (m_pNamedPropertyArray) {	
+		CValue* val = GetProperty(inName);
+		if (NULL != val) 
+		{
+			val->Release();
+			m_pNamedPropertyArray->erase(inName);
+			return true;
+		}
+	} 
+	
+	char err[128];
+	if (m_pNamedPropertyArray)
+		sprintf(err, "attribute \"%s\" dosnt exist", inName.ReadPtr());
+	else
+		sprintf(err, "attribute \"%s\" dosnt exist (no property array)", inName.ReadPtr());
+	
+	PyErr_SetString(PyExc_AttributeError, err);
 	return false;
 }
 
@@ -755,7 +762,8 @@
 
 int	CValue::_delattr(const STR_String& attr)
 {
-	RemoveProperty(attr);
+	if (!RemoveProperty(attr)) /* sets error */
+		return 1;
 	return 0;
 }
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp	2008-09-03 03:37:47 UTC (rev 16346)
+++ trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp	2008-09-03 06:43:07 UTC (rev 16347)
@@ -329,7 +329,7 @@
 	{"getNumAxes",	 (PyCFunction) SCA_JoystickSensor::sPyNumberOfAxes,	METH_NOARGS,	NumberOfAxes_doc},
 	{"getNumButtons",(PyCFunction) SCA_JoystickSensor::sPyNumberOfButtons,METH_NOARGS,	NumberOfButtons_doc},
 	{"getNumHats",	 (PyCFunction) SCA_JoystickSensor::sPyNumberOfHats,	METH_NOARGS,	NumberOfHats_doc},
-	{"getConnected", (PyCFunction) SCA_JoystickSensor::sPyConnected,	METH_NOARGS,	Connected_doc},
+	{"isConnected", (PyCFunction) SCA_JoystickSensor::sPyConnected,		METH_NOARGS,	Connected_doc},
 	{NULL,NULL} //Sentinel
 };
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-09-03 03:37:47 UTC (rev 16346)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp	2008-09-03 06:43:07 UTC (rev 16347)
@@ -1036,11 +1036,15 @@
 
 int KX_GameObject::_setattr(const STR_String& attr, PyObject *value)	// _setattr method
 {
-	if (attr == "mass")
+	if (attr == "mass") {
+		PyErr_SetString(PyExc_AttributeError, "attribute \"mass\" is read only");
 		return 1;
+	}
 	
-	if (attr == "parent")
+	if (attr == "parent") {
+		PyErr_SetString(PyExc_AttributeError, "attribute \"mass\" is read only\nUse setParent()");
 		return 1;
+	}
 		
 	if (PyInt_Check(value))
 	{
@@ -1106,7 +1110,7 @@
 				}
 				return 1;
 			}
-			
+			PyErr_SetString(PyExc_AttributeError, "could not set the orientation from a 3x3 matrix, quaternion or euler sequence");
 			return 1;
 		}
 		





More information about the Bf-blender-cvs mailing list