I need a function that computes the device up-time into seconds.
Means, I want to have a function that I can call from several scripts
But I never get a return value with my attempt.
Please advise.
Thanks!
Function (simplyfied to test)
# MyFunc01.rsc
:global myFunc do={
:local weeks 0;
:local days 1;
:local hours 22;
:local minutes 33;
:local seconds 44;
# return value should be 167624sec
:return (($weeks*86400*7) + ($days*86400) + ($hours*3600) + ($minutes*60) + ($seconds) );
}
Caller
$myFunc never delivers the return value which was computed in the function.
# TestMyFunction02.rsc
:global myFunc [:parse [/system script get myFunc01 source]];
:local UpTimeInSeconds 0;
:set $UpTimeInSeconds [$myFunc];
[/log info ("\n\n Up since $UpTimeInSeconds sec \n")];
[/log info ("\n\n Up since [$myFunc] sec \n")];
MyFunc01.rsc or myFunc01 so is the name of the script with a capital or not? I do not put .rsc behind the filename because they are already in the script section.
Changed your code:
# myFunc01
:local weeks 0;
:local days 1;
:local hours 22;
:local minutes 33;
:local seconds 44;
# return value should be 167624sec
:return (($weeks*86400*7) + ($days*86400) + ($hours*3600) + ($minutes*60) + ($seconds) );
The caller
# TestMyFunction02
:global myFunc [:parse [/system script get myFunc01 source]];
:local UpTimeInSeconds 0;
:set $UpTimeInSeconds [$myFunc];
:log info "Up since1 $UpTimeInSeconds sec";
:log info "Up since2 [$myFunc] sec";