🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Resetting the script

Started by
3 comments, last by WitchLord 19 years, 4 months ago
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..
Advertisement
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

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

ah, great thanks :)
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?
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.

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

This topic is closed to new replies.

Advertisement