🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

AngelScript 1.8.0 WIP #2 (2004/06/26)

Started by
46 comments, last by WitchLord 19 years, 12 months ago
I compiled the test framework and it just comes up with press any key to quit. The error occurs when I try to register the function, not call it. Tell me, what steps do I need to take before I can start registering functions?
Advertisement
Since the test framework passed all the tests without any errors at least I know the library is working ok.

The only thing you should have to do before registering functions is to create the engine. Take a look at the source code for the test framework for individual examples showing how to register functions.

I'm thinking that you are having a linkage problem. Somehow your application is not using the same interface or calling convention that the library is. Are you the same Anonymous Poster that was previously using version 1.6.1?

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

yes. I guess I will just erase everything angelcode and install it again. I'll let you know what happens.
Yep, I accidentally was mixing the different versions. But, now I have another error (and only one version of angelscript). When I try to register a classes' methods, I get
assertion errors. The registering of stuff is in a different source file, but includes a global header containing the various class definitions.

the registering:

r = engine->RegisterObjectMethod("CGame", "int AddFont(char *filename)", asMETHOD(CGame::AddFont), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("CGame", "int AddAnim(char *filename, int frames, int width, int height)", asMETHOD(CGame::AddAnim), asCALL_THISCALL); assert( r >= 0 );
r = engine->RegisterObjectMethod("CGame", "int AddSound(char *filename)", asMETHOD(CGame::AddSound), asCALL_THISCALL); assert( r >= 0 );
What WIP version are you using?

With the latest you should take the method pointer with asMETHOD(classname, methodname).

What is the value of r that you receive? Check the value and compare with error codes in angelscript.h.

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

I downloaded the latest WIP from
http://www.angelcode.com/angelscript/files/angelscript_sdk_180WIP_20040626.zip

Either I downloaded the wrong WIP, or you forgot to update the zip file.
Oh, I guess I'm using the right one. The error code is -11 or asINVALID_TYPE.

here is how I register the function:
r = engine->RegisterObjectMethod("CGame", "int AddFont(char *filename)", asMETHOD(CGame, AddFont), asCALL_THISCALL); assert( r >= 0 );

Does the class I'm referencing need to be an actual class or an object?


Since you get asINVALID_TYPE I assume that you haven't registered the CGame object type.

engine->RegisterObjectType("CGame", sizeof(CGame), flags);

or

engine->RegisterObjectType("CGame", 0, 0);

The second variant prevents the script from instantiating variables of that type, effectively forcing the script to use CGame objects provided by the application either through a global variable or a function.

If you choose the first variant you should read the reference about what the last parameter should be (flags).

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

I'm sorry that I'm retarded but I can't get this to work. You were right I forgot to uncomment the line registering the CGame type. Now, I get error 10 (asINVALID_DECLARATION). Here is how it happens:

r = engine->RegisterObjectType ("CGame", 0, 0); hge->System_Log("%d", r); assert( r >= 0 );
r = engine->RegisterObjectMethod("CGame", "int AddSound(char*)", asMETHOD(CGame, AddSound), asCALL_THISCALL|asCALL_RETURNBYVAL); hge->System_Log("%d", r); assert( r >= 0 );

No worries :)

This time your problem is that you are trying to declare the method parameter as "char*", which isn't recognized by AngelScript. You could however use either one of int8, uint8, or bits8.

I suspect that you wish to be able to send a string to this function, in which case you will have to register a string factory function. If you don't register the string factory, AngelScript won't let you use the string constants. Take a look at the code for registering the bstr for more info on how to do that. You can even use that code directly in your application.

Register bstr source

If you decide to use the bstr code as it is, you'll have to remember to release the bstr that you receive. Or you could change your method to accept a reference to a bstr, as the script engine will be responsible for releasing the memory. I suggest you do the following:

#include "bstr.h"RegisterBStr(engine);engine->RegisterObjectMethod("CGame", "int AddSound(const bstr &)", asMETHOD(CGame, AddSound), asCALL_THISCALL);


Where the AddSound method looks like this:

int CGame::AddSound(const asBStr *_str) // Or char **{  // Dereference the parameter. By receiving the string by  // reference we don't have to deallocate the memory.   char *str = *_str;   // Continue working with str just as you would normally do  ...}


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