Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Davaris1

Member Since 11 May 2007
Offline Last Active Apr 08 2012 07:49 PM
-----

Topics I've Started

Constructors that take parameters?

26 September 2011 - 06:17 AM

I want an object to behave like this in AngelScript, but am unable to get it to work.

// AngelScript Code:
	
ZedScriptW p(ptrToZedEntityID1);
ZedScriptW s(ptrToZedEntityID2);


This part seems to work.

// C++
r = engine->RegisterObjectType("ZedScriptW", sizeof(ZedScriptW), asOBJ_VALUE|asOBJ_APP_CLASS|asOBJ_APP_CLASS_CONSTRUCTOR|asOBJ_APP_CLASS_DESTRUCTOR); assert( r >= 0 );

r = engine->RegisterObjectBehaviour("ZedScriptW", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ZedScriptW_Constructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );
	
r = engine->RegisterObjectBehaviour("ZedScriptW", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(ZedScriptW_Destructor), asCALL_CDECL_OBJLAST); assert( r >= 0 );


However I can't figure out how to create a constructor that accepts multiple parameters.

This is my attempt

// C++

r = engine->RegisterObjectBehaviour("ZedScriptW", asBEHAVE_CONSTRUCT,  "void f(ZedEntityID @)",  asFUNCTIONPR(ZedScriptW_Constructor_ZedEntityID, (ZedScriptW*,  ZedEntityID*), void), asCALL_CDECL_OBJLAST); assert( r >= 0 );

This is the code for the constructor that takes a parameter. The function is called when I run it, but ownerID points to garbage.

// C++

void ZedScriptW_Constructor_ZedEntityID(ZedScriptW *memory, ZedEntityID *ownerID)
{
   new(memory) ZedScriptW();

   if (ownerID) 
 	memory->SetComponent(ownerID->GetOwner());
}

Can anyone help?


Edit:
I think I have figured it out while writing this post. asCALL_CDECL_OBJLAST is the hint. So I have swapped the params around.


r = engine->RegisterObjectBehaviour("ZedScriptW",  asBEHAVE_CONSTRUCT,  "void f(ZedEntityID  @)",  asFUNCTIONPR(ZedScriptW_Constructor_ZedEntityID,  ( ZedEntityID*, ZedScriptW*), void), asCALL_CDECL_OBJLAST); assert( r  >= 0 


void ZedScriptW_Constructor_ZedEntityID(ZedEntityID *ownerID, ZedScriptW *memory)

Hopefully all of the above is correct. If not please let me know. :)

Assertion Error in scriptmgr.cpp

23 September 2011 - 08:18 AM

Hi WitchLord,
   I was just testing your demo game and got an assertion of r = -10 at line 59 and line 87, in scriptmgr.cpp.

I downloaded the tarball from here:

http://angelscript.s...elscript/trunk/

It works fine when I use scriptstdstring.h, but when I use my version of it, those functions do not register.

Edit:
I have found my mistake. In my version of scriptstdstring.cpp I used "String" instead of "string".

One Module Per Entity, Or One Modual to Rule Them All?

18 September 2011 - 09:49 PM

What the best way to go about this?  I have some code from an old tutorial and they are loading all the files into one module and then calling function names from that module.

// Load weapons script file
if (LoadScript( pScriptEngine, "common.as", MAIN_MODULE ) < 0)
{
pScriptEngine->Release();
cout << "Failed to load script file." << endl;
Pause();
return -1;
}

// Load weapons script file
if (LoadScript( pScriptEngine, "weapons.as", MAIN_MODULE ) < 0)
{
pScriptEngine->Release();
cout << "Failed to load script file." << endl;
Pause();
return -1;
}

// Load main script file that runs in synch with the game loop
if (LoadScript( pScriptEngine, "main.as", MAIN_MODULE ) < 0)
{
pScriptEngine->Release();
cout << "Failed to load script file." << endl;
Pause();
return -1;
}



So is it better to create an additional module for each creature in a game, or should I have only 1 module and have unique "main functions", based on each creature's name?

Creature1Main()
{
}

Creature2Main()
{
}

etc.

RegisterObjectType returns asINVALID_NAME

11 September 2011 - 02:38 PM

I'm trying to get my first script working using the C4 String class. Unfortunately it is hitting an assert and is returning asINVALID_NAME here:

r = engine->RegisterObjectType("String<>", sizeof(String<>), asOBJ_VALUE | asOBJ_APP_CLASS_CDAK); Assert( r >= 0 );


I have replaced string with String<> all through scriptstdstring.cpp, so I am not sure what I should do. Any suggestions?

Compatibility Issues with C4 Engine [Solved]

08 September 2011 - 11:11 AM

Hi,
I'm trying to get AngelScript working in the C4 Engine and am getting the following error messages when I compile:

stdlib.h(599) : error C2485: '__restrict' : unrecognized extended attribute

Microsoft Visual Studio 9.0\VC\include\new(58) : error C2084: function 'void *operator new(size_t,void *)' already has a body

enginecode\C4PrefixWindows.h(1391) : see previous definition of 'new' new(63) : error C2084: function 'void operator delete(void *,void *)' already has a body

enginecode\C4PrefixWindows.h(1401) : see previous definition of 'delete'

Microsoft Visual Studio 9.0\VC\include\xlocale(342) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc

Do you have any suggestions as to how I can get around them? I assume he has these settings in C4 for a good reason, so is there any way I can make AngelScript work with C4?

PARTNERS