Page 1 of 1

parameters for scripting

Posted: Sat Apr 05, 2008 2:22 pm
by baumie
Hi
I want to know if there's a way of passing parameters to a MT script. For instance I want to change the rate-limits for centain user groups can I write one script and get the limits from parameters passed to the script or must I do a script for each rate limit and group

Re: parameters for scripting

Posted: Mon Apr 07, 2008 9:33 am
by mrz
You can use global variables, for example,

simple script "myScript":
{
:global myVar;
:put &myVar;
}

Before calling "myScript" set "myVar" value:

{
:global myVar 999;
/system script run myScript;
}

Re: parameters for scripting

Posted: Thu Apr 10, 2008 9:38 am
by baumie
Thanks I never thought of that but it will solve my problem

Re: parameters for scripting

Posted: Wed Feb 13, 2019 12:13 am
by Etz
Sorry for necro posting, but how do you pass multiple parameters to script?

Would this work?:
{
:global myVar1 999;
:global myVar2 9999;
/system script run myScript;
}
Considering that MyScript has global scope variables MyVar1 and MyVar2 present?

Re: parameters for scripting

Posted: Wed Feb 13, 2019 4:25 pm
by Jotne
Should work as long as you declare your global variables in the sub script like this:
:global myVar1
:global myVar2
PS, you do not need ut use ; at the end of the line, only to separate multiple commands at the same line.
So your script could be written:
{
:global myVar1 999
:global myVar2 9999
/system script run myScript
}

Re: parameters for scripting

Posted: Thu Sep 12, 2019 4:24 pm
by A9691
You can pass parameters to script files run with /import. For example:
Content of fact.rsc:
:if ($1 > 1) do={
	:global fact
	:set $result ([$fact ( $1 - 1 )]*($1))
} else={
	:set $result 1
}
Define fact function:
:global fact do={/import "fact.rsc"; return $result}

Testing:
[admin@bkeniko] > :put [$fact 3]

Script file loaded and executed successfully

Script file loaded and executed successfully

Script file loaded and executed successfully
6
[admin@bkeniko] > 

Is there any documentation on this?
(tested on v6.40.8 )

Re: parameters for scripting

Posted: Fri Sep 13, 2019 12:40 pm
by SiB
Is there any documentation on this? (tested on v6.40.8 )
.
I think it's new, I cannot see about passing variable by global function.to /import feature. This is like recursion . Works in 6.45.3