Registering an uninstanciable reference type: Identifier 'XXX' is not a data type

Started by
3 comments, last by WitchLord 9 years, 10 months ago

I have a C++ type that I don't want to instantiate from scripts and only use as handles, preferably by passing it to the constructor for script classes that should be able to interact with it.

I followed the documentation and used asOBJ_NOCOUNT and did not provide a factory behavior. Actually, this is all I did (never mind the wrapper):


engine.register_object_type("Scene", 0, asOBJ_REF | asOBJ_NOCOUNT);

engine.register_object_method("Scene", "const string &name() const", asMETHODPR(scene::Scene, name, () const, const std::string&));

When I try to load a script that looks like this:


class Scene_test
{
	Scene_test(Scene@ scene)
	{
		scene_ = scene;
	}

	void on_scene_loaded()
	{
		print("Hello World");
	}

	Scene@ scene_;
};

I get an error stating "Identifier 'Scene' is not a data type".

Any idea what I'm missing?

Advertisement

You haven't used SetDefaultNamespace() have you?

I also have a bunch of reference types which I don't want script to be able to create, only reference existing(-in-C++) ones. I register them in the same way as you. However, due to the namespace, I have to refer to them in script as:

mynamespace::Scene@

I don't see any problem in your code.

For what line is the code indicating this error? For the constructor declaration or the class member?

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Oh, namespace was indeed a problem. Sorry. The default namespace was set to "scene", but writing scene::Scene in the script did not change the error message. As a test I changed the namespace to "", after which I get "There is no copy operator for the type 'Scene' available."

The copy operator error is because you're doing a value assign in the constructor. You need to prefix the left hand expression with @ to indicate a handle assign (i.e. replacement of the reference).

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement