Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 12 Mar 2012
Online Last Active Today, 04:59 PM

Topics I've Started

Polymorphism and casts.

02 April 2012 - 02:08 PM

Greetings again.

I tumbled across another problem which seems to be quite huge:
I registered an Interface from C++, named 'BaseEntity'.
A script class "AbstractBaseEntity" inherits that Interface.
A script class "AbstractNPC" inherhits "AbstractBaseEntity"

That results in a rather simple class hierarchy...

So far, so good.
I also have registered a method 'instanciate' for a global property named System. It works well, and instanciates my entities just fine. It is registered to return a handle '@BaseEntity' ... which works fine, too.
I can use the InterfaceSpecific methods then.

But now comes the clue:
I cant cast!

The following code does not work:

// Those are self designed includes. They work fine. I made a scriptdump to verify right behavior.
#include scripts/entity/IBaseEntity.as
#include scripts/entity/NPC.as

void main() {
	// System pretty sure is registered. But check to be sure... <img src='http://public.gamedev.net//public/style_emoticons/default/tongue.png' class='bbc_emoticon' alt=':P' />
	if( System is null ) {
		println("System is null.Aborting.");

	// Instanciate an entity.
	BaseEntity@ ent=System.instanciate("AbstractBaseEntity");

	if (ent !is null) {
		println("Received Entity(BaseEntity) with id: "+ent.getID());
	} else {
		println("Ent is null... :'( ");

	 // Prints:
	AbstractBaseEntity@ ent2=cast<AbstractBaseEntity>(ent);
	if (ent2 !is null)
		println("We have an AbstractBaseEntity at hand, btw.");

	 // Works fine.
	ParamList par();
	BaseEntity@ ent3=System.instanciate("AbstractNPC","AbstractNPC @AbstractNPC(int,string)",par);
	 //ent3 is an BaseEntity by now. Its true. I checked it. (:
	AbstractNPC@ ent4=cast<AbstractNPC>(ent);
	if (ent4 !is null)
		println("We have an AbstractNPC at hand, btw.");


Received Entity(BaseEntity) with id: 0
AbstractNPC created. ( <- This is printed in the constructor of AbstractNPC )

I just updated to the newst version of angelscript. So far everything seems to work fine.
Help appreciated.

With warm regards,
Kuro Sei.

PS: Shall i have missed some important details or in case you need some closer specification of my registrations or the script classes i will update those asap. But for now i dont see any reasyon why i should pump up this overextended wall of text even more.

Returning from AS ( Comprehension Question )

20 March 2012 - 12:09 PM

Okay, it's me again.
Most likely my question is easy to solve again, but i got hung there for 2 days now. Maybe i searched google and the forum for the wrong key words?

Well: The alst few days i was wrapping my head around AngelScript as good as possible. Now i have the problem that i want a generic method to receive return Values from Angelscript.

It looks like that:

template<class T> T getReturnG() {
  asIScriptObject* sObj=*(asIScriptObject**)scriptContext->GetReturnObject();
  T ent=(T)sObj;
  return ent;

//Some specis for it.
template<> int getReturnG() {
  return (int)scriptContext->GetReturnDWord();

template<> float getReturnG() {
  return scriptContext->GetReturnFloat();
template<> double getReturnG() {
  return scriptContext->GetReturnDouble();

It works fine with reference types, float, int etc.
But when i try to receive an std::string i get an error. It's a value type so i guess it has something to do with that?
( I registered strings with registerStdString() btw)
The compiler tells me, that asIScriptObject* can't be converted to std::string.

I got no idea how to retrieve value types with this convention. Any ideas?

Sorry, if the question is kinda dumb... ^^"

Edit: Oh i forgot:

Thats how i retrieve the return value.
std::string str=sys->getReturnG<std::string>();

Thats how i registered the function:
"string getString()"

AddScriptSection crashs

12 March 2012 - 07:07 AM

Im new to angelscript and honestly didnt program in C++ for a while so please be gentle to me ;)

I had no problems getting angelscript integrated in my IDE and stuff, but when i tried around with the ScriptEngine a bit i got a nasty error i cant solve.

My specs are:
Microsoft Visual Studio 2010
Windows 7 (64 bit)
Angelscript 22202

I use Angelscript as a static lib.

The code which does problems is this one ( Broke it down to be shorter. Posted Image )

  // Create the script engine
  asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION);

  int r = engine->SetMessageCallback(asFUNCTION(MessageCallback), 0, asCALL_CDECL);

  // get the main module ( Or create it...)
  main_module=engine->GetModule("main", asGM_ALWAYS_CREATE);
  // Register the standard string for use in AngelScript
  // Ready.

ScriptManager::ScriptManager(std::string name, std::string path, bool dump)
  // First set up the general stuff we need.

  // Load the designated file.
  std::string script=LoadScriptFile(path);

  main_module->AddScriptSection(name.c_str(), script.c_str()); // PROBLEMS HERE


The last bit of code (namely: main_module->AddScriptSection(name.c_str(), script.c_str()); ) breaks my application. Visual Studio catchs the Exception. Edit: The messageCallback gives no output.

The debugger tells me that i got memory violation. __vfptr cant be interpreted as it seems.

I would be very gratefull if anyone knew an answer since im pretty much in to learn the AngelScript Scriptengine and language since it seems to fit my needs pretty well. Posted Image

If you need more information i missed for some reason feel free to ask and i will answer asap.