Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Passing reference as parameter


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 yamashi-   Members   -  Reputation: 105

Like
0Likes
Like

Posted 10 February 2013 - 07:00 PM

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 !



Sponsor:

#2 saejox   Members   -  Reputation: 714

Like
0Likes
Like

Posted 10 February 2013 - 10:15 PM

SetArgObject works just fine.

Please post some code.



#3 yamashi-   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 February 2013 - 05:23 AM

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() :(



#4 Andreas Jonsson   Moderators   -  Reputation: 3198

Like
0Likes
Like

Posted 11 February 2013 - 09:22 AM

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?


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

#5 yamashi-   Members   -  Reputation: 105

Like
0Likes
Like

Posted 11 February 2013 - 01:03 PM

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-, 11 February 2013 - 01:21 PM.


#6 Andreas Jonsson   Moderators   -  Reputation: 3198

Like
0Likes
Like

Posted 11 February 2013 - 02:19 PM

I haven't begun working with C++11 yet, but I must say the template variadic arguments does look neat.


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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS