Difficulties with functions

Hi guys,

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";

Thanks very much, msatter!

Function call, based on your updates, works very well now.

The step to assign the return value to a variable and then to write it to the log file via

:log info "Up since1 $UpTimeInSeconds sec";

leads to the wanted result “Up since1 167624 sec”.

Just one open issue:

:log info "Up since2 [$myFunc] sec";

delivers “Up since2 (code) sec” in the log file.
Tried a lot of syntax variants to get “Up since2 167624 sec”, but unsuccessful.
Any ideas?

Thanks!

I think you can only show messages in the logand any manipulations have to be done in advance.

Makes sense, Thanks msatter.