Jump to content











Photo
- - - - -

Run Command Enhancement


  • Please log in to reply
5 replies to this topic

#1 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 18 August 2009 - 11:18 AM

I introduced that variables passed to a Run command, can be defined as OUT variables.
That means they can be set / changed from inside the Run.

Sample:

[Variables]

%A%=16

%b%=25

%Result%=blabla



[process]

Echo,"%A% %b% %Result%"

Run,%ScriptFile%,getMax,%a%,%b%,OUT:%Result%

Echo,"%A% %b% %Result%"

Run,%ScriptFile%,getMaxAlt,OUT:%a%,%b%

Echo,"%A% %b%"



[getMax]

// #3 will contain the bigger number

If,#2,BIGGER,#1,Set,#3,#2

Else,Set,#3,#1



[getMaxAlt]

// #1 will contain the bigger number

If,#2,BIGGER,#1,Set,#1,#2

Produces:
OUT_Params.gif

Peter

#2 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 18 August 2009 - 11:50 AM

:whistling: Took me a while, before i've got what you've done.
With the ordinary parameters the contents is handed over, with the OUT: switch the variable itself is handed over.
Since the variable can then be used for in- and output, like in example 2, maybe a different name for the OUT: Switch would be a good idea.

Does this also work, if i call a section in another script?

:cheers:

#3 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 18 August 2009 - 12:26 PM

:whistling: Took me a while, before i've got what you've done.
With the ordinary parameters the contents is handed over, with the OUT: switch the variable itself is handed over.
Since the variable can then be used for in- and output, like in example 2, maybe a different name for the OUT: Switch would be a good idea.

Does this also work, if i call a section in another script?

:cheers:

This mechanism causes that after returning from the Run (also in a different script) eventually the parameter #? is copied into the variable %????%.

Therefore it is NOT a passing the variable by reference. That is nearly impossible in the current WB structure.

That also makes a different switch name not very sencefull.

For those who are interested, the code:
Part one before doing the Run
if AnsiPos(',OUT:', ScriptMemo.CommaText) > 0 then

		  begin

			hasOut := true;

			OutVars := TStringList.Create;

			OutVars.Add('');

			if hlpMemo = nil then

			  hlpMemo := TStringList.Create

			else

			  hlpMemo.Clear;

			hlpMemo.CommaText := AnsiUpperCase(OriginalCommand);

			for i := 3 to hlpMemo.Count - 1 do

			begin

			  if AnsiStartsStr('OUT:', hlpMemo[i]) then

				OutVars.Add(AnsiReplaceText(hlpMemo[i], 'OUT:', ''))

			  else

				OutVars.Add('');

			end;

		  end;
Part 2 after returning from Run:
if hasOut then

		  begin

			for i := 1 to OutVars.Count - 1 do

			begin

			  if OutVars&#91;i&#93; <> &#39;&#39; then

			  begin

				SetVars&#40;&#39;Set,&#39; + OutVars&#91;i&#93; + &#39;,&#39; + TranslateVariables&#40;&#39;#&#39; + IntToStr&#40;i&#41;&#41;&#41;;

			  end;

			end;

			OutVars.Free;

			hlpMemo.Free;

			hlpMemo &#58;= nil;

		  end;

Peter

#4 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 18 August 2009 - 01:05 PM

This mechanism causes that after returning from the Run (also in a different script) eventually the parameter #? is copied into the variable %????%.

Therefore it is NOT a passing the variable by reference. That is nearly impossible in the current WB structure.

That also makes a different switch name not very sencefull.

If you put it like this, i have to agree. :whistling:
Though other names could be: r/w: for switching from 'read only' to 'read/write' parameters or i/o: for switching from 'input only' to 'input/output'.

Thinking about it.
Is there any reason to keep the old way and not completely replace it with the new, without the switch?

:cheers:

#5 pscEx

pscEx

    Platinum Member

  • Team Reboot
  • 12707 posts
  • Location:Korschenbroich, Germany
  • Interests:What somebody else cannot do.
  •  
    European Union

Posted 18 August 2009 - 01:24 PM

Is there any reason to keep the old way and not completely replace it with the new, without the switch?

Besides processing time, What about the existing scripts which trust that the variables are passed readonly and not changed?

Peter

Peter

#6 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 18 August 2009 - 01:55 PM

I don't follow, when the old scripts were created, the variable could not be changed, hence there can be no code which would change it now, that it is possible.
And the new scripts will be developed right from the start, with the knowledge that changing is possible.

But if there is a need for a read only variable passing, it is a completely different situation.

:whistling:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users