0

I have a problem to make use of AngelScripts global functions inside a C++-application.

In my .cpp file I have the function:

int multi(int x, int y)
{
    int z = x * y;
    cout << x << endl;
    cout << y << endl;
    return z;
}

I'm registering it by using:

engine->RegisterGlobalFunction("int multi(int &out, int &out)", asFUNCTION(multi), asCALL_CDECL);

In my .as file I call the function like this:

multi(1, 2);

So in this case I want x to be 1 and y to be 2, but when I print the values with cout it's something like x = 4318096 and y = 4318100.

I can't figure out where my mistake is. I appreciate any help I can get.

Zydar
  • 85
  • 1
  • 8

2 Answers2

1

You register this function wrong. It should be:

engine->RegisterGlobalFunction("int multi(int, int)", asFUNCTION(multi), asCALL_CDECL);

Out means this function will use this parameter as output.

Tomashu
  • 515
  • 1
  • 11
  • 20
0

It should be:

engine->RegisterGlobalFunction("int multi(int, int)", asFUNCTION(multi), asCALL_CDECL);

When you use out it expects you to set the out value. And it doesn't get set before it enters the function. I'd you do it as I mentioned it will be set and doesn't expect it to be set. Good luck.

josliber
  • 43,891
  • 12
  • 98
  • 133