Sign in to follow this  
LogicalError

Resetting the script

Recommended Posts

How can i reset a script to it's initial state? (global variables set to their default values etc.) As it is currently, i don't see how that's possible without recompiling everything.. This would be usefull if, for instance, you want to restart a game. Otherwise you might have situations where a game would restart with different values (the leftover values from the previous game) which could lead to hard to find bugs.. I tought this would happen if i simply released my context and created a new one.. But apparently context is only used to handle an execution of a function? (unless i'm missing something?) Maybe it would be nice if there would be some superstructure over context which would represent a script's current state.. By simply destroying it and creating a newer one you'd start over at square one.. It might also be a nice way to seperate different modules.. You could have a state structure for a client module, and a state structure for a server module for instance.. You'd never want them to communicate to eachother directly, and you'd want to be able to restart the state of the client, but not of the server an example (angelscript):
int test = 0;

void main()
{
	counter = test;
	test++;
}
counter is a global property.. Now everytime i call the function main, counter becomes larger. What i would like is a mechanism which would allow me to reset 'test' to 0 Now i suppose i could discard a module and reload it, but that's hardly elegant..

Share this post


Link to post
Share on other sites
You've understood everything perfectly. :) Currently the only way to reset the state of a module, would be to recompile it.

A method for resetting the state of a module would be very convenient. I'll implement it for the next version. In fact, I already planned to implement this method a long time a go, but somehow it was forgotten along the way. Thanks for reminding me of it again.

If you feel like customizing the library yourself before I can release the next version, all you need is basically a method in asCModule that does the following:

void asCModule::Reset()
{
CallExit();
CallInit();
}

and a method in asCScriptEngine to access the module method:

int asCScriptEngine::ResetModule(const char *_module)
{
asCModule* module = GetModule(_module, false);
if( module == 0 ) return asNO_MODULE;

module->Reset();

return 0;
}

Regards,
Andreas

Share this post


Link to post
Share on other sites
Just curious, but wasn't there some work done to save the state of a script? Couldn't he save the start state, then restore it later?

Share this post


Link to post
Share on other sites
It is not yet possible to save the state of the contexts.

It is possible to save the module's compiled bytecode and reload it again, which would also reset the values of the global variables.

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