Advertisement

Passing a pointer of a script object to C++

Started by July 01, 2007 12:03 PM
8 comments, last by WitchLord 17 years, 4 months ago
Hi again!! (You're gonna hate me heh) :P I have a C++ class method registered in AngelScript like this:

	if (ScriptMgr::RegisterObjectMethod(_className, "bool AddEntity(const IsoSprite@+, int col, int row, int layer)",asMETHODPR(IsoMap, AddEntity, (IsoSprite*, int, int, int), bool),asCALL_THISCALL) < 0)
		return false;

So I want to pass a reference to an object in AngelScript with this code:

IsoMap      _iso;
IsoSprite[] _sprite;

.
.
.

_iso.AddEntity(@_sprite[0], col, row, 0);

But i have an error that says "Invalid reference". So, I had to do something like this:

IsoMap      _iso;
IsoSprite@[] _sprite;

.
.
  for (int i=0; i < 100; i++) {
    IsoSprite sprtemp;
    
    @_sprite = @sprtemp;
    
    if (!_sprite.Load("data/iso/residencia1.spr"))
      return false;
  }

_iso.AddEntity(_sprite[0], col, row, 0);

Well, is there a way to do that without all of this? I've tried also registering the class with ∈, but it copies the object so when i try to modify some of the properties in AngelScript, in C++ the object stills the same because it is a copy of the original. Thanks a lot!!
=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8
I hate you... ;)


No, actually it's great that you're finding these bugs. It shows that you're pushing the library farther than anyone else has. It's always a problem when you're the first to step on new grounds, but don't worry I'll help you through it.

I'll have to take a closer look at this problem to see what may be causing it. It does however seem to be a bug in the implicit conversion somewhere.

Regards,
Andreas

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
Thanks!!! :)

By the way, the "Invalid reference" error is a string thrown by the AngelScript compiler, not the Visual Studio debugger.
=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8
I've detected and fixed this bug. I'll check in the code fix tonight I hope.

The problem was actually with explicitly taking the handle of the array element. If you let the compiler implictly do it for you it worked correctly.

Example:

IsoMap      _iso;IsoSprite[] _sprite;..._iso.AddEntity(_sprite[0], col, row, 0);


This same bug plagued class members as well.

Regards,
Andreas

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`ve checked in the code under revision 168.

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 still having the same problem. When I do this:

IsoMap      _iso;IsoSprite[] _sprite;int which = 0;bool Initialize() {  if (!_iso.Load("data/iso/map.imp"))    return false;  _sprite.resize(100);    if (!_sprite[0].Load("data/iso/pacman.spr"))    return false;      for (int i=1; i < 100; i++) {    if (!_sprite.Load("data/iso/residencia1.spr"))      return false;  }         _iso.AddEntity(_sprite[0], 0, 0, 0);     return true;}


i've also tried with _iso.AddEntity(@_sprite[0], 0, 0, 0);

I'm doing it right?

[Edited by - mckracken on July 4, 2007 10:57:34 AM]
=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8
Advertisement
I forgot to mention that the error is an assertion when loading bytecode in:
[source lang=cpp]	READ_NUM(count);	module->scriptFunctions.Allocate(count, 0);	for( i = 0; i < count; ++i ) 	{		func = NEW(asCScriptFunction)(module);		ReadFunction(func);		module->scriptFunctions.PushLast(func);		engine->SetScriptFunction(func);	}


in "module->scriptFunctions.PushLast(func);" line.


=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8
I found a problem and the fix for it. However I do not know if it is the same problem that you're having, since this actually broke the code when saving the byte code and not when loading. The changes I made to the compiler are the following:

as_compiler.cpp: 282		byteCode.InstrPTR(BC_FREE, builder->module->RefObjectType(outFunc->objectType));as_compiler.cpp: 905				ctx->bc.InstrPTR(BC_REFCPY, builder->module->RefObjectType(ctx->type.dataType.GetObjectType()));as_compiler.cpp: 2952		bc->InstrPTR(BC_REFCPY, builder->module->RefObjectType(lvalue->dataType.GetObjectType()));as_compiler.cpp: 6616				ctx->bc.InstrPTR(BC_REFCPY, builder->module->RefObjectType(ctx->type.dataType.GetObjectType()));


The changes are the added call to builder->module->RefObjectType. Can you apply those changes and then try to see if it resolves your problem?

I'll try to find the time to check in this code tonight. But if you can give it a try before that it would be great.

Regards,
Andreas

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!!! It works perfectly! Thanks!!!!
=====================================Regards,Juan Pablo (McKrackeN) Bettini Psychoban Official Site:http://www.psychoban.comPsychoban on iTunes App Store:http://itunes.apple.com/us/app/psychoban/id378692853?mt=8
Excellent!

If no new bugs are discovered I should be able to release version 2.8.1 this weekend.

It will be great to finally be able to move on to implementing new features instead of just fixing bugs. :D

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