• Advertisement
Sign in to follow this  

Passing reference as parameter

This topic is 1806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

 

I am trying to pass an exiting object as a reference to a function but I can't get it to work...

I have tried NPC@ and NPC& as type and nothing seems to work...

I use SetArgObject and give it a pointer to my object (I don't want to copy it because I want to be able to call functions on that object).

If I put the object in a global variable it works just fine...

 

Could you give me some insights ?

 

Thanks !

Share this post


Link to post
Share on other sites
Advertisement

Here it is :

 

NPC npc;
context->Prepare(func);
context->SetArgObject(0, &npc);
context->Execute();
context->Unprepare();

 

And the AS code :

 

void OnNew(NPC @npc)
{
print(npc.GetName());
}

 

 Note that it does work if I set mt NPC to a global parameter so there is nothing wrong with my GetName() :(

Share this post


Link to post
Share on other sites

The code you showed should work. For parameters by handle, like in your case, SetArgObject will call Addref on the object and put the pointer on the stack.

 

Is any of the calls to context's methods returning an error? i.e. a negative value?

Share this post


Link to post
Share on other sites

The thing being I don't have ref counting on these objects (my application manages everything).

 

And no no negative value what's so ever :s

 

My bad, my variadic template call was actually doing a hard copy of the object and passing a stack address that had been deleted.

 

Here is my code if someone wants an easy way to start : https://github.com/yamashi/SkyrimOnline/blob/master/Client/Src/Server/Src/Game/ScriptEngine.hpp

Edited by yamashi-

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement