forked from bartvdbraak/blender
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()
This commit is contained in:
parent
b818b1a164
commit
cfa07e8d2b
@ -119,6 +119,7 @@ PyObject *PyObjectPlus::_getattr(const STR_String& attr)
|
||||
|
||||
int PyObjectPlus::_delattr(const STR_String& attr)
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "attribute cant be deleted");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -126,7 +127,8 @@ int PyObjectPlus::_setattr(const STR_String& attr, PyObject *value)
|
||||
{
|
||||
//return PyObject::_setattr(attr,value);
|
||||
//cerr << "Unknown attribute" << endl;
|
||||
return 1;
|
||||
PyErr_SetString(PyExc_AttributeError, "attribute cant be set");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*------------------------------
|
||||
|
@ -391,16 +391,23 @@ float CValue::GetPropertyNumber(const STR_String& inName,float defnumber)
|
||||
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 @@ CValue* CValue::ConvertPythonToValue(PyObject* pyobj)
|
||||
|
||||
int CValue::_delattr(const STR_String& attr)
|
||||
{
|
||||
RemoveProperty(attr);
|
||||
if (!RemoveProperty(attr)) /* sets error */
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ PyMethodDef SCA_JoystickSensor::Methods[] = {
|
||||
{"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
|
||||
};
|
||||
|
||||
|
@ -1036,11 +1036,15 @@ PyObject* KX_GameObject::_getattr(const STR_String& attr)
|
||||
|
||||
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 @@ int KX_GameObject::_setattr(const STR_String& attr, PyObject *value) // _setattr
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_AttributeError, "could not set the orientation from a 3x3 matrix, quaternion or euler sequence");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user