Sign in to follow this  

Resetting the script

This topic is 4688 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

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

This topic is 4688 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.

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