change variable with step

Features wanted...
fogg
Posts: 32
Joined: 15 Jul 2014 16:13
Location: Going around the World

change variable with step

Post by fogg »

Hello ! :kidding: 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! :idea:
s404:signature not found.

highend
Posts: 14567
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: change variable with step

Post by highend »

I hope xyplorer has this ability
No, you can't change any variables during the debugging process
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: change variable with step

Post 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.

fogg
Posts: 32
Joined: 15 Jul 2014 16:13
Location: Going around the World

Re: change variable with step

Post 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. ?
s404:signature not found.

fogg
Posts: 32
Joined: 15 Jul 2014 16:13
Location: Going around the World

Re: change variable with step

Post by fogg »

Thank to TheQwerty. I did not see your text. I will try your advise.
s404:signature not found.

fogg
Posts: 32
Joined: 15 Jul 2014 16:13
Location: Going around the World

Re: change variable with step

Post 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.
s404:signature not found.

highend
Posts: 14567
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: change variable with step

Post 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).
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: change variable with step

Post 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;

highend
Posts: 14567
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: change variable with step

Post by highend »

@TheQwerty

OT: Gz for your 4k post! (actually I'm 2 posts too late^^)
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: change variable with step

Post by TheQwerty »

OT: @highend: TY!

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: change variable with step

Post 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 ... :ugeek:
(Name it "planned mistake" :biggrin: )

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 :appl: )

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: change variable with step

Post 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 ... :ugeek:
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.

Filehero
Posts: 2713
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: change variable with step

Post 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?

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: change variable with step

Post 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');
  }
}
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Filehero
Posts: 2713
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: change variable with step

Post 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.

Post Reply