How to pass variable between scripts

Is there any way to pass variables between scripts?
It seems that I can not access variables that are declared global in one script from another script.

Ex.
In script 1:
:global 64kdownload 64000

On the command line:
:environment print
shows: "“64kdownload”=64000

In script 3:
/queue type set “user-download” pcq-rate=$64kdownload

Script three will not run properly. Any ideas?

Take a look at this.
http://forum.mikrotik.com/t/script-help/25278/1

-Louis

In the scripts that use global variables, but not change them, use this:

:global 64kdownload
/queue type set "user-download" pcq-rate=$64kdownload

to use global variable you have to declare it - if it is global and already have value - you will be able then access that value.

also note, that script should be in {} signs, or each line will count as separate script.

Pardon me, but I am not sure I understand. What do you mean by “separate script”? I know I use <?php ?> for php, but I saw nothing of the brackets in the examples. I use none in mine unless to group stuff. If I am doing something that may cause me challenges, I would like to know. Maybe a reference or wiki?

BTW I do not use the commands unless assigning them or getting a return value. So it would always be
:local returnval [/command]
I do not use
/command
anywhere.

Hello, I have similar problem.
I have 2 script

name="test1" source=:global test "12345"; 
name="test2" source=:put $test;

And I can't display global variable from script

[admin@test] /system script> run test1
[admin@test] /system script> environment print

NAME VALUE

0 test 12345
[admin@test] /system script> run test2

[admin@test] /system script>

You have to declare it:

name="test1" source=:global test "12345"; 
name="test2" source=:global test; :put $test;

To use variable from other script just re-declare the variable without initializing it.

script1

:global previousIP "1.2.3.4"
:put $previousIP

will display 1.2.3.4

script2

:global previousIP
:put $previousIP

will display 1.2.3.4

I pass values by using named variables, there is no need for globals here:
ex:

:local rtt [$getRTT target=$target intf=$intfP count=$pcount timeout=$ptimeout]

:global getRTT do={
#:log info “getRTT: target: $target, intf: $intf, count: $count, timeout: $timeout”

If you read the title

How to pass variable between scripts

You see that global is needed or you can write data to a file.

Actually I did see it, but … if the scripts are related say script1 call on script2, named variables can be used.
If one can’t call on the other then that won’t fly naturally.

In other way, another option for a developer