Proposed Evaluate command to simplify scripting

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Proposed Evaluate command to simplify scripting

Post by gdyvig » Wed Oct 15, 2008 5:51 pm

//Macro Schuduler's ability to expand variables is very powerful.
//However, it is limited to expansions of variable parameters, not names.
//Variable expansions allow scripts to be greatly simplified.
//Eliminates need for lenghy if statements to evaluate arguments.
//They are also useful for data driven macros where the data is a Macro Scheduler command string.
//In short, this proposal wishes a variable be able to contain a Macro Scheduler command name and parameters and execute it by means of a simple expansion.

// This script illustrates current capabilities, limitations, workarounds, and two proposed solutions.
//Our company's standard is VAREXPLICIT 1
//Should also apply to VAREXPLICIT 0
Let>VAREXPLICIT=1
Include>IncludeLib
gosub>StartEventHandlers
SRT>EvaluateCommand
//EvaluateCommand,CommandString
DeleteFile>C:\tempmacro.scp
WriteLn>C:\tempmacro.scp,nWLNRes,Include>IncludeLib
WriteLn>C:\tempmacro.scp,nWLNRes,gosub>StartEventHandlers
WriteLn>C:\tempmacro.scp,nWLNRes,%CommandString%
Macro>C:\tempmacro.scp
END>EvaluateCommand


SRT>EvaluateCommandArgs
//EvaluateCommand,CommandString
Let>VAREXPLICIT=0
DeleteFile>C:\tempmacro.scp
WriteLn>C:\tempmacro.scp,nWLNRes,Include>IncludeLib
WriteLn>C:\tempmacro.scp,nWLNRes,gosub>StartEventHandlers
WriteLn>C:\tempmacro.scp,nWLNRes,%EvaluateCommandArgs_Var_1%
Macro>C:\tempmacro.scp
Let>VAREXPLICIT=1
END>EvaluateCommandArgs

Let>x=113
Let>y=784
Let>MouseAction1=MouseMove
Let>MouseAction2=LClick
Let>MouseAction3=RClick
////////////////////////////WHAT WORKS ALREADY///////////////////////////
//This works
MouseMove>%x%,%y%

//////////////////////////WHAT DOES NOT WORK//////////////////////

//Command name variable expansions display in the logfile
//but the commands are not executed, so these statements do not work
%MouseAction1%>%x%,%y%
%MouseAction2%

////////////////////////////////// WORKAROUNDS////////////////////////////
//This workaround works
//bury comma in a variable
Let>CommandString=MouseMove>%x%,%y%
gosub>EvaluateCommand
Let>CommandString=LClick
gosub>EvaluateCommand
wait>5
//This variation of workaround is more readable
Let>Command1=MouseMove>%x%,%y%
gosub>EvaluateCommandArgs,%Command1%
Let>Command2=LClick
gosub>EvaluateCommandArgs,%Command2%
//This also works because there are no commas
gosub>EvaluateCommandArgs,RClick

//The readable workaround works fails when commas needed for the parameters
gosub>EvaluateCommandArgs,MouseMove>%x%,%y%
gosub>EvaluateCommandArgs,%MouseAction1%>%x%,%y%

//The only other workarounds involve lengthy "if/else" statements to parse the command string.

////////////////////////CONCLUSION///////////////////////////////
//The workarounds do the job, but incur lots of overhead setting up the temp macro
//The workaround will fail for compiled macros run in a non MS environment.
//A cleaner approach would be to extend the language to expand/execute varibles as commands.
//Example:
%MouseAction1%>%x%,%y%
//Or if that is not feasible, a new Evaluate command that works in current macro's scope.
//Example:
Evaluate>MouseMove,%x%,%y%

Code: Select all



gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

How I intended to use this enhancement.

Post by gdyvig » Thu Oct 16, 2008 8:06 pm

I was trying to create a subroutine or macro that would let me create a simple script listing some imagefiles and what I wanted to do with each image.

Something like this:

SRT>MoveClick
WaitScreenImage>%MoveClick_Var_1&
FindImagePos>%MoveClick_Var_1%,SCREEN,0,X,Y,NumFound
if>NumFound=1
MouseMove>{%X_0%+%MoveClick_Var_2%,>{%X_0%+%MoveClick_Var_2%}
Evaluate>%MoveClick_Var_2%
endif
END>MoveClick

Evalulate>gosub>MoveClick,%imagefile1%,0,0,LClick
Evalulate>gosub>MoveClick,%imagefile1%,0,20,RClick

Notice that because MouseMove is a command I can pass parameters to it in my subroutine. But I cannot do that for the LClick or RClick commands. Without the proposed Evaluate command (or the macro on the fly workaround) the MoveClick Subroutine would need an if statement for each of the possible click commands.

This particular situation could also be solved with a new Mouse command that accepts each of the click actions as a parameter. The Evaluate command would be more general.

The idea came from another language where I found it useful in a variety of situations, especially in data driven testing.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts