Jump to content
  • Advertisement
Sign in to follow this  

Failure in CreateScriptObject when adding class instance to dictionary

This topic is 1428 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

class foo {}

class FooAndData
    FooAndData ( foo@ _foo )
        @memberVar = _foo;

    foo@ memberVar;

    // todo: add more stuff

void main()
    dictionary dict = { {'entry', foo()} }; // OK
    dict['additionalEntry'] = foo();        // OK
    @dict['additionalEntry'] = foo();       // OK

    dictionary dict2 = { {'entry', FooAndData(null)} }; // OK
    //dict2['additionalEntry'] = FooAndData(null);      // "Failed in call to function 'CreateScriptObject' (Code: -6)"
    @dict2['additionalEntry'] = FooAndData(null);       // OK

I'm confused by the failure of the middle call in the second group. Why can I instantiate a parameter-less instance of foo and add it to the dictionary, but I cannot instantiate FooAndData(null) and add it to the dictionary? In my mind, the dictionary is logically storing object instances, not handles to object instances.

Edited by iraxef

Share this post

Link to post
Share on other sites

    dictionary dict = { {'entry', foo()} };  // This stores the foo instance by value
    dict['additionalEntry'] = foo();          // This copies of the foo instance (value assignment)
    @dict['additionalEntry'] = foo();       // This stores a handle to the foo instance (handle assignment)


The CreateScriptObject fails for FooAndData because the class doesn't have a default constructor and opAssign method or copy constructor (not included automatically since you implemented a non-default constructor).


When initializing the dictionary with the initalization list the dictionary was able to bypass this by storing the actual FooAndData instance, since it was a temporary and wouldn't be used elsewhere.




I'll see if I can come up with a better error message. Unfortunately I don't think it will be possible to detect the error during compile time, since the compiler doesn't know what the dictionary will do with the class on the opAssign call.

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!