Sign in to follow this  

asINVALID_ARG troubles

Recommended Posts

I'll currently run into a dead end trying to fix this error. I'm trying to pass a asIScriptObject ("*asObj") to the script and keep receiving the asINVALID_ARG return code. The factory function returns a valid pointer to the asIScriptObject and everything runs smoothly until I pass that same pointer to the script engine for the "update function".
I would be more than happy to post more code as needed to help.
Here's some of the revelant source code

C++ file "Script_Manager.cpp"
[source lang="java"]
void Script_Manager::init()
//...code left out for simplicity....//
// Register the object methods
r = ScriptEngine->RegisterObjectMethod("SceneNode", "vector3 &getPosition() const", asMETHOD(SceneNode, getPosition), asCALL_THISCALL); assert( r >= 0);
r = ScriptEngine->RegisterObjectMethod("SceneNode", "void setPosition(const vector3 &in)", asMETHODPR(SceneNode, setPosition, (const Vector3 &pos), void), asCALL_THISCALL); assert( r >= 0);

//Register all the reference types so the Script ScriptEngine can interpret them in the scripts
//Register the 'GameManager' which is really an alias for the BaseApplication Singleton class
r = ScriptEngine->RegisterObjectType("GameManager", 0, asOBJ_REF | asOBJ_NOCOUNT);

//////////GAME ENTITY REGISTERING//////////
//Register the 'GameEntity' type which is really an alias for the Game_Entity class
r = ScriptEngine->RegisterObjectType("GameEntity", 0, asOBJ_REF);

//Register the 'GameEntity' addRef/release behaviours
r = ScriptEngine->RegisterObjectBehaviour("GameEntity", asBEHAVE_ADDREF, "void addRef()", asMETHOD(Game_Entity, addRef), asCALL_THISCALL);
r = ScriptEngine->RegisterObjectBehaviour("GameEntity", asBEHAVE_RELEASE, "void release()", asMETHOD(Game_Entity, release), asCALL_THISCALL);
//r = ScriptEngine->RegisterObjectMethod("GameEntity", "void setID(int newID)", asMETHOD(Game_Entity, setID), asCALL_THISCALL);
r = ScriptEngine->RegisterObjectMethod("GameEntity", "SceneNode@ getSceneNode()", asMETHOD(Game_Entity, getSceneNode), asCALL_THISCALL); assert( r >= 0);

//local instance that shouldn't be used outside of this 'init' function
CScriptBuilder ScriptBuilder;

ScriptBuilder.StartNewModule(ScriptEngine, "ScriptModule");

r = ScriptBuilder.AddSectionFromFile("");

r = ScriptBuilder.BuildModule();

ScriptModule = ScriptEngine->GetModule("ScriptModule");

//create a pointer to a asIScriptContext
ctx = ScriptEngine->CreateContext();
ctx->SetExceptionCallback(asFUNCTION(ExceptionCallback), 0, asCALL_CDECL);

// Get the object type
asIObjectType *type = ScriptEngine->GetObjectTypeById(ScriptModule->GetTypeIdByDecl("Player"));

ScriptFunction = type->GetFactoryByDecl("Player@ Player(GameEntity@ Entity)");

UpdateFunction = type->GetMethodByDecl("void Update()");

C++ file "Entity_Manager.cpp"
[source lang="cpp"]void Entity_Manager::addGame_Entity(Game_Entity* addedEntity)

void Entity_Manager::spawnGame_Entity(BaseApplication* GameManager, std::string filename, Ogre::Vector3 pos)
Game_Entity* entity = new Game_Entity();
entity->gEntity = GameManager->getSceneMgr()->createEntity(filename, filename + ".mesh");
entity->gSceneNode = GameManager->getSceneMgr()->getRootSceneNode()->createChildSceneNode();
//set the spawn position


//This is called in the Gameplay State... (left out for simplicity)
void Entity_Manager::update(BaseApplication* GameManager)
for(EntityIterator = EntityList.begin(); EntityIterator != EntityList.end(); ++EntityIterator)

C++ file "Game_Entity.cpp"
[source lang="cpp"]void Game_Entity::init(BaseApplication* GameManager)
int result;
result = GameManager->getScriptManager()->getScriptContext()->SetArgObject(0, this);
result = GameManager->getScriptManager()->getScriptContext()->Execute();
asObj = *(asIScriptObject**)GameManager->getScriptManager()->getScriptContext()->GetAddressOfReturnValue();


void Game_Entity::update(BaseApplication* GameManager)
int result;
result = GameManager->getScriptManager()->getScriptContext()->Prepare(GameManager->getScriptManager()->getUpdateFunction());
//this appears to be the source of my woes....
result = GameManager->getScriptManager()->getScriptContext()->SetArgObject(0, this->asObj);
result = GameManager->getScriptManager()->getScriptContext()->Execute();

AngelScript file ""
[source lang="plain"]class Player
Player(GameEntity @Entity)
health = 100;
@self = Entity;

void Update()
self.getSceneNode().setPosition(self.getSceneNode().getPosition() + vector3(.25, 0, 0));

GameEntity@ self;
int health;


Share this post

Link to post
Share on other sites
The Player::Update() method doesn't take any arguments, so any call to SetArg...() would be wrong.

You need to call ctx->SetObject(this->asObj) to set the object for which the method should be invoked.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this