[request] Reset Local Static Variables

0 favourites
  • 8 posts
From the Asset Store
"Easy Local Notifications" enhances games with customizable local notifications.
  • Ashley, there is a Reset Global Variables action, but there is no Reset Local Static Variables action.

    This is an issue when trying to reset a layout- all the local static variables retain their values. I have many many local static variables in various groups, it'd be a pain to have to manually reset all them.

    Can we get an action that takes care of this?

  • me too im interestead on this feature available on Construct

  • In case anyone is interested, and in case Ashley doesn't implement it (although it seems rather simple to add)- I copied the global variable reset action and modified it (changed "all_global_vars" to "all_local_vars") to work as a custom plugin:

    	Acts.prototype.ResetLocals = function ()
    	{
    		var i, len, g;
    		for (i = 0, len = this.runtime.all_local_vars.length; i < len; i++)
    		{
    			g = this.runtime.all_local_vars[i];
    			g.data = g.initial;
    		}
    	};
    [/code:2x2c6sjh]
    When the action is run, it resets all the local variables to their default (including static variables).
  • In case anyone is interested, and in case Ashley doesn't implement it (although it seems rather simple to add)- I copied the global variable reset action and modified it (changed "all_global_vars" to "all_local_vars") to work as a custom plugin:

    > 	Acts.prototype.ResetLocals = function ()
    	{
    		var i, len, g;
    		for (i = 0, len = this.runtime.all_local_vars.length; i < len; i++)
    		{
    			g = this.runtime.all_local_vars[i];
    			g.data = g.initial;
    		}
    	};
    [/code:401d8xeg]
    When the action is run, it resets all the local variables to their default (including static variables).
    

    very interesting

    help me understand better, so this reset ALL variables of the project at the same time? locals and globals too?

  • Not the global variables. There is already a system action that you can use to reset the global variables.

    I basically looked at the code for that action (for resetting the globals) and copied it into my own plugin and edited it so that it resets local variables instead of globals.

    I think this action resets ALL the local variables in the entire project regardless of whether a group is enabled or disabled.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Not the global variables. There is already a system action that you can use to reset the global variables.

    I basically looked at the code for that action (for resetting the globals) and copied it into my own plugin and edited it so that it resets local variables instead of globals.

    I think this action resets ALL the local variables in the entire project regardless of whether a group is enabled or disabled.

    ok so the "reset global variables" action remain available

    then this piece of code you make create another action field right?

    how implement this? we have to edit some C2 file?

  • You'd have to add it to a custom plugin.

    You can take the example template plugin that scirra provides and make your own plugin with the code. It's a pretty simple process.

  • You'd have to add it to a custom plugin.

    You can take the example template plugin that scirra provides and make your own plugin with the code. It's a pretty simple process.

    understood, usually i never use plugins but this time i think is exception

    thanks for sharing, i test it on a new project

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)