I'm trying to add keyboard support to a codebase that has so far only supported PS3 controllers - there are two structs that I'd like to expose to AS: ps3_controller::event and keyboard::event. Here's how I'm binding both:
void bind_ps3_controller(asIScriptEngine* Engine)
{
using namespace ps3_controller;
int Result = 0;
Result = Engine->SetDefaultNamespace("ps3_controller");
Result = Engine->RegisterGlobalProperty("const int down", const_cast<int*>(&ps3_controller::down));
assert(Result >= 0);
Result = Engine->SetDefaultNamespace("ps3_controller::button");
Result = Engine->RegisterGlobalProperty("const int cross", const_cast<int*>(&ps3_controller::button::cross));
assert(Result >= 0);
Result = Engine->SetDefaultNamespace("ps3_controller::analog");
Result = Engine->RegisterGlobalProperty("const int LStickX", const_cast<int*>(&ps3_controller::analog::LStickX));
Result = Engine->RegisterGlobalProperty("const int LStickY", const_cast<int*>(&ps3_controller::analog::LStickY));
Result = Engine->RegisterGlobalProperty("const int RStickX", const_cast<int*>(&ps3_controller::analog::RStickX));
Result = Engine->RegisterGlobalProperty("const int RStickY", const_cast<int*>(&ps3_controller::analog::RStickY));
//
Result = Engine->SetDefaultNamespace("ps3_controller");
Engine->RegisterObjectType("event", sizeof(ps3_controller::event), asOBJ_VALUE | asOBJ_POD);
Engine->RegisterObjectProperty("event", "uint64 time", asOFFSET(event, time));
Engine->RegisterObjectProperty("event", "int source", asOFFSET(event, source));
Engine->RegisterObjectProperty("event", "int state", asOFFSET(event, state));
Engine->RegisterObjectProperty("event", "float value", asOFFSET(event, value));
//
Result = Engine->SetDefaultNamespace("");
}
void bind_keyboard(asIScriptEngine* Engine)
{
using namespace keyboard;
int Result = 0;
Result = Engine->SetDefaultNamespace("keyboard");
Engine->RegisterEnum("event_type");
Engine->RegisterEnumValue("event_type", "key_down", keyboard::key_down);
Engine->RegisterEnumValue("event_type", "key_up", keyboard::key_up);
Engine->RegisterEnumValue("event_type", "key_repeat", keyboard::key_repeat);
Engine->RegisterObjectType("event", sizeof(keyboard::event), asOBJ_VALUE | asOBJ_POD);
Engine->RegisterObjectProperty("event", "uint64 time", asOFFSET(event, time));
Engine->RegisterObjectProperty("event", "event_type type", asOFFSET(event, type));
Engine->RegisterObjectProperty("event", "int code", asOFFSET(event, code));
//
Result = Engine->SetDefaultNamespace("");
}
However I seem to get the following output when I try to register keyboard event's time member:
"Property (1, 8) : ERR : Name conflict. 'time' is an object property.
(0, 0) : ERR : Failed in call to function 'RegisterObjectProperty' with 'event' and 'uint64 time'"
What am I missing here? As far as I understand, the keyboard bindings should be in a keyboard namespace and the object's shouldn't alias. What am I doing wrong?
I was using 2.23.1. I'm trying to transition to the latest release but the script array addon seems to have build errors with that one - am I doing something wrong or hasn't the addon been updated to match newer API?
scriptarray.cpp:80:9: Cannot initialize a variable of type 'int' with an rvalue of type 'asIScriptFunction *'
scriptarray.cpp:99:27: No member named 'GetFactoryIdByIndex' in 'asIObjectType'; did you mean 'GetFactoryByIndex'?
scriptarray.cpp:99:9: Cannot initialize a variable of type 'int' with an rvalue of type 'asIScriptFunction *'
scriptarray.cpp:301:25: No member named 'CopyScriptObject' in 'asIScriptEngine'; did you mean 'CreateScriptObject'?
scriptarray.cpp:301:47: Too many arguments to function call, expected 1, have 3
scriptarray.cpp:697:20: Cannot initialize a parameter of type 'asIScriptFunction *' with an lvalue of type 'int'
scriptarray.cpp:794:21: Cannot initialize a parameter of type 'asIScriptFunction *' with an lvalue of type 'const int'
scriptarray.cpp:809:21: Cannot initialize a parameter of type 'asIScriptFunction *' with an lvalue of type 'const int'
scriptarray.cpp:1061:14: No member named 'CopyScriptObject' in 'asIScriptEngine'; did you mean 'CreateScriptObject'?
scriptarray.cpp:1061:35: Too many arguments to function call, expected 1, have 3
scriptarray.cpp:1112:29: No member named 'GetMethodIdByIndex' in 'asIObjectType'; did you mean 'GetMethodByIndex'?
scriptarray.cpp:1112:18: Assigning to 'int' from incompatible type 'asIScriptFunction *'
scriptarray.cpp:1117:28: No member named 'GetMethodIdByIndex' in 'asIObjectType'; did you mean 'GetMethodByIndex'?
scriptarray.cpp:1117:17: Assigning to 'int' from incompatible type 'asIScriptFunction *'
Thanks, I updated the add-on code and now it builds. I'm getting a different error from the same keyboard binding code now:
Property (1, 1) : ERR : Identifier 'event_type' is not a data type
(0, 0) : ERR : Failed in call to function 'RegisterObjectProperty' with 'event' and 'event_type type'
The code is:
void bind_keyboard(asIScriptEngine* Engine)
{
using namespace keyboard;
int Result = 0;
Result = Engine->SetDefaultNamespace("keyboard");
Engine->RegisterEnum("event_type");
Engine->RegisterEnumValue("event_type", "key_down", keyboard::key_down);
Engine->RegisterEnumValue("event_type", "key_up", keyboard::key_up);
Engine->RegisterEnumValue("event_type", "key_repeat", keyboard::key_repeat);
Engine->RegisterObjectType("event", sizeof(keyboard::event), asOBJ_VALUE | asOBJ_POD);
Engine->RegisterObjectProperty("event", "uint64 time", asOFFSET(event, time));
Engine->RegisterObjectProperty("event", "event_type type", asOFFSET(event, type));
Engine->RegisterObjectProperty("event", "int code", asOFFSET(event, code));
//
Result = Engine->SetDefaultNamespace("");
}