Redefining parameters

(imported topic written by ilmtMike)

It seems silly to have to ask this but how do I redefine a parameter?

parameter “myName” = “bob” <–initially set the parameter

I have tried and failed with all of the following.

set parameter “myName” = “fred”

parameter “myName” = “fred”

parameter set "myName = “fred”

set "myName = “fred”

(imported comment written by gearoid)

Checking the actionscript
it looks like you can’t:

You can’t reset a parameter that already has a value.
When this occurs, the client

will abort the action at the line that is attempting to reset the parameter. Any

errors that result from evaluating the expression will be handled by making the

named parameter become undefined

(imported comment written by ilmtMike)

That will teach me not to read only the “rules of the parameter” section :stuck_out_tongue:


(imported comment written by jgstew)

Updated: the strikethrough parts are wrong

I believe the reason for this is that the parameters are set BEFORE the actionscript is executed.
This would mean that the parameter would always have whatever you set it to the last time you set it, so to prevent that they are only able to be set once.

For this reason, you should always set parameters at the TOP of your script.

(imported comment written by MattPeterson)

Parameters cannot be set twice within an action, but they are set when the action is running. They are evaluated before the action runs as well, so if a parameters fails to evaluate prior to running, then the action will fail with an error. However parameters are actually set when the action runs. Say your task modifies a file, and you have a parameter to read a line of that file after it was modified, the parameter will read whatever is in that file when it runs the line to set the parameter.

Here is a simple example that proves this behavior.

waithidden cmd.exe /c echo Bob >> c:\test.txt

parameter “test.txt” = “{if exist file “c:\test.txt” then line 1 of file “c:\test.txt” else “”}”

the “if exist file” part is important, because without it the relevance would fail to evaluate prior to the action running if that file didn’t exist.

(imported comment written by jgstew)

Ah, right. This is where my confusion comes from. I am so used to it failing when something didn’t exist, I forgot about this work-a-round that proves the opposite of what I originally posted.