tiagolr / dconsole

Haxe game-like console that provides runtime acess to methods, variables and more.
MIT License
169 stars 16 forks source link

Variables in functions called by commands don't work correctly when the state changes. #52

Closed Yaru2585 closed 9 years ago

Yaru2585 commented 9 years ago

So, if I have a Bool, let's call it randomBool

private var _randomBool:Bool = false;

and a function, let's call it toggleBool

function toggleBool(args:Array<String>):Void
{
       _randomBool = !_randomBool;
}

and register a command that calls this function

DC.registerCommand(toggleBool,"toggleBool"[...]

it works perfectly and the bool toggles, but if I change the State, with FlxG.switchState or with FlxG.resetState or with FlxG.resetGame, the command keeps executing, since if I put traces inside the function, they execute, but the bool doesn't toggle. Is this a known issue and/or has solution?

Yaru2585 commented 9 years ago

Okay, solved! I only had to put the vars as Static. Sorry!

tiagolr commented 9 years ago

Yeap would tell you to do so, nice.