I'm starting to play with AS and I have a question about contexts. My understanding of contexts is limited, and I was assuming that contexts were independent of each other, so that if the same script code was executed, the global variables could hold different values in different contexts. Let me explain quickly. Here's a simple script:
int x = 0;
void test()
{
x++;
Print(x);
}
Now in C++, I declare two contexts:
int func = pEngine->GetFunctionIDByDecl("dummy", "void test()");
asIScriptContext *ctx1 = pEngine->CreateContext();
res = ctx1->Prepare(func);
res = ctx1->Execute();
ctx1->Release();
asIScriptContext *ctx2 = pEngine->CreateContext();
res = ctx2->Prepare(func);
res = ctx2->Execute();
ctx2->Release();
The execute() call of ctx1 will print x with a value of 1, as expected.
Now when I create the second context, I'm expecting x to be reset to 0, and the execute() call of ctx2 to display x with a value of 1 too. But it displays a value of 2, like if variables values were shared between contexts.
Is this the expected behavior ? If so, is there any way to make the variables context dependent ? Thanks..
Y.