Advertisement

Create class by value of string

Started by September 08, 2014 11:53 PM
2 comments, last by WitchLord 10 years, 2 months ago

Basically what I'm trying to do is create an object by the value of a string (the string will refer to the Class that the object needs to be). This is to be used in an Item/Inventory system for the game I'm working on. What will happen is I'll save items to a folder based on their object type. Then later when I load those, I need to be able to recreate that object according to the class it used. Is this possible in AngelScript?

Yes, it is perfectly possible. You can use asIScriptModule::GetObjectTypeByName to get the type and then asIScriptEngine::CreateScriptObject to create the instance.

If you plan to serialize the content of objects you can use the CreateUninitialedObject instead and the manually initializing the members by iterating over them.

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

Advertisement

Sorry I was talking about doing this from within a script, not from within C/C++

You can do it from the script if your application registers a function that takes the object type by name and returns the type in a variable argument type or the generic script handle add-on.

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