Hi guys!
I’ve created some scripts at work that abstract the user’s technical configuration and instead just ask questions, the user answers them and the answer is validated.
Everything works perfectly, but now I’m trying to turn these answer validations into functions, as the script is getting long. Take a look below:
# Function - Validating response
:global checkYN do={while ($a != "y" && $a != "n") do={
:put "----------------------------------------------------------------------------------------------------"
:put "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
:put " ERROR: Invalid response."
:put "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
:put "----------------------------------------------------------------------------------------------------"
:local b do={:return}
:put "\r\n***** y or n *****\r\n"
:set $a [$b]
:put "var $a after set inside function"
}
}
# Asking if the user want to configure the identity
:global readIdentity do={:return}
:put " Do you want to configure the Mikrotik identity?
\r\n***** y or n *****\r\n"
:global identityResponse [$readIdentity]
# Calling function
:put "var $identityResponse raw"
$checkYN a=$identityResponse
:put "var $identityResponse after function checkYN"
The problem is that the variable I’m passing is not receiving the updated value after the function. It’s the first time I’ve created a function, I think it’s something to do with scopes, but I’ve tried several ways and haven’t managed to solve it.
I appreciate any help ![]()