Page 1 of 2
change variable with step
Posted: 22 Feb 2016 19:39
by fogg
Hello !

I am trying to write some scripts in xyplorer and when I use "Try Script" option and see mistakes. But I cannot fix variables by editing in "Variables On Stack" . I hope xyplorer has this ability. Thank you!

Re: change variable with step
Posted: 22 Feb 2016 19:47
by highend
I hope xyplorer has this ability
No, you can't change any variables during the debugging process
Re: change variable with step
Posted: 22 Feb 2016 20:02
by TheQwerty
You actually can change global and permanent variables while the stepping dialog is active but the new value will not be used in the command that is currently being stepped.
Code: Select all
::global $a = 'hello';step;echo $a;echo $a;
While the stepping dialog is waiting on you start XY again but use the
/script parameter to change the value:
Code: Select all
XYplorer.exe /script="::global $a='blah';"
The first echo will still show 'hello', but the second will show 'blah'.
I wouldn't recommend actually using this or relying on this to not change though.
Re: change variable with step
Posted: 22 Feb 2016 20:04
by fogg
But I see little trouble in very large script. And if changing a variable this time allows me to keep running this script. Other wise I have to again start at the beginnning again. ?
Re: change variable with step
Posted: 22 Feb 2016 20:06
by fogg
Thank to TheQwerty. I did not see your text. I will try your advise.
Re: change variable with step
Posted: 22 Feb 2016 20:11
by fogg
TheQwerty wrote:You actually can change global and permanent variables while the stepping dialog is active but the new value will not be used in the command that is currently being stepped.
Code: Select all
::global $a = 'hello';step;echo $a;echo $a;
While the stepping dialog is waiting on you start XY again but use the
/script parameter to change the value:
Code: Select all
XYplorer.exe /script="::global $a='blah';"
The first echo will still show 'hello', but the second will show 'blah'.
I wouldn't recommend actually using this or relying on this to not change though.
Thank you. But still I cannot edit un-global variables.
Re: change variable with step
Posted: 22 Feb 2016 20:20
by highend
XY is not an IDE and debugging is limited to step or a "?" in front of a command. Global variables and permanent ones have their purpose but polluting the current scope with them is not what I'd call "good practice".
Don't forget that you can unstep; as well, so you normally only debug a smaller part of your script by surrounding that part with step / unstep and you can always spit out values to check if something is working correctly or not (either by writing a log or using the script command status if you don't want to be bothered with a gui output that requires user interaction).
Re: change variable with step
Posted: 22 Feb 2016 20:31
by TheQwerty
You can always insert temporary Inputs to make this possible - even bundling it up in a function if desired, though it does add cruft to the "release" version:
Code: Select all
function DEBUG($name, &$v) {
if (true) {
$v = Input('Debugger',"Modifying $name", $v, 'm');
}
}
"Main"
$v = 'hello';
DEBUG('$v', $v);
echo $v;
Re: change variable with step
Posted: 22 Feb 2016 20:36
by highend
@TheQwerty
OT: Gz for your 4k post! (actually I'm 2 posts too late^^)
Re: change variable with step
Posted: 22 Feb 2016 21:16
by TheQwerty
OT: @highend: TY!
Re: change variable with step
Posted: 22 Feb 2016 22:46
by PeterH
TheQwerty wrote:You can always insert temporary Inputs to make this possible - even bundling it up in a function if desired, though it does add cruft to the "release" version:
Code: Select all
function DEBUG($name, &$v) {
if (true) {
$v = Input('Debugger',"Modifying $name", $v, 'm');
}
}
"Main"
$v = 'hello';
DEBUG('$v', $v);
echo $v;
Hm - do I see it right?
If yes, then you have to add the DEBUG-line after each line of code setting a variable.
OK: if you happen to know the line you made a mistake in ...
(Name it "planned mistake"

)
To ease up a release version, you can expand:
Code: Select all
function DEBUG($name, &$v) {
if (true) {
$v = Input('Debugger',"Modifying $name", $v, 'm');
}
}
"Main"
$debug = true; // debugging active
$v = 'hello';
If ($debug) { DEBUG('$v', $v); }
echo $v;
For release version change $debug to false.
(I sometimes really use that to (not) output debug messages

)
Re: change variable with step
Posted: 23 Feb 2016 03:04
by TheQwerty
PeterH wrote:Hm - do I see it right?
If yes, then you have to add the DEBUG-line after each line of code setting a variable.
OK: if you happen to know the line you made a mistake in ...
Yes... it's intended for localized debugging. It's not so much that you need to know where the mistake is, but where there's no turning back with that particular variable/value.
This entire thread is things which are not recommended.
PeterH wrote:To ease up a release version, you can expand. . . For release version change $debug to false.
Not needed, just change the true in DEBUG to false. It will still be stepped through but nothing will occur within the function - same as your variable, but with the benefit you're not worrying about keeping that variable in scope.
But again none of this is actually recommended for long-term use.
Re: change variable with step
Posted: 23 Feb 2016 06:28
by Filehero
TheQwerty wrote:Code: Select all
function DEBUG($name, &$v) {
if (true) {
--^^^^^^^^
$v = Input('Debugger',"Modifying $name", $v, 'm');
}
}
What's the purpose of this if-clause?
Re: change variable with step
Posted: 23 Feb 2016 06:53
by bdeshi
so that you can later replace it with false, and all debug prompts will die.
Code: Select all
function DEBUG($name, &$v) {
if (false) {
--^^^^^^^^^
$v = Input('Debugger',"Modifying $name", $v, 'm');
}
}
Re: change variable with step
Posted: 23 Feb 2016 09:05
by Filehero
Thanks, so I supposed right. I think, I would define a perm var switch for that.
@TheQwerty: good idea!
SammaySarkar wrote:so that you can later replace it with false, and all debug prompts will die.