Jump to content
  • Advertisement
Sign in to follow this  

Problem with registering global behaviour

This topic is 3938 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to register automatic conversion (assignment) from abstract Value class to integer, but it doesn't seem to work. Non-abstract class does just fine and I can register other functions easily for Value, just not the global behaviour. The global behaviour registration works fine with DoubleValue, a non-abstract class derived from Value. The only difference between these two that I have been able to find is that Value is abstract. But the function that does the assignment is static, so the fact that Value is abstract should definitely not break anything or probably should do so in compilation time, not later. I don't seem to get any error messages from AngelScript callback either, although it is registered and works in other cases. I extracted some of the code:
// Abstract baseclass
class Value {
  virtual double getIntValue() = 0;

int assignValueToInt(Value* value) {
  return value->getIntValue();

// Subclass of value
class DoubleValue : public Value {
  double getDoubleValue() { return 0.0; }

int assignDoubleValueToInt(DoubleValue* value) {
  return value->getIntValue();

// Regist
r = engine->RegisterObjectType("Value", sizeof(Value), asOBJ_CLASS_CA); assert( r >= 0 );

// Register dummy constructor that gives an error etc...

// This works fine
r = engine->RegisterObjectBehaviour("String", asBEHAVE_ASSIGNMENT,
                                      "String& f(const Value &in)",
                                      asCALL_CDECL_OBJFIRST); assert( r >= 0 );

// Doesn't work, assert aborts, return code is -5 (invalid argument)
	r = engine->RegisterGlobalBehaviour(asBEHAVE_ASSIGNMENT,
                                      "int f(const Value &in)",
                                      asCALL_CDECL); assert( r >= 0 );

r = engine->RegisterObjectType("DoubleValue", sizeof(DoubleValue), asOBJ_CLASS_CA); assert( r >= 0 );

// Works just fine
r = engine->RegisterGlobalBehaviour(asBEHAVE_ASSIGNMENT,
                                      "int f(const DoubleValue &in)",
                                      asCALL_CDECL); assert( r >= 0 );
I don't even have any more ideas where the problem might be... I am probably overlooking something, but I have tried to find the problem for two days by now, so any help is appreciated. Mr Jones

Share this post

Link to post
Share on other sites
What you're trying to do isn't supported yet.

Assignment behaviours aren't allowed to be registered as global behaviours. I'll have to investigate why AS is accepting it for the DoubleValue, it shouldn't have.

Adding support for cast behaviours is a high priority to me, which will allow you to do what you want. But for now the best thing you can do is to register a normal function to do what you want, e.g:

// C++ registered function
int cint(const DoubleValue &in);

// In AngelScript
DoubleValue val;
int i = cint(val);


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!