I defined the variable... but the function doesn't process it.

I have been going round and round for 2 weeks now.

I need to set a global variable at start up or at start of day to make a schedule.
I later have 1 SCRIPT that is checking several things. One of which being whether the time range falls with in the schedule.

The script appears to not process the :global variable when brought into a function so I made this smaller script just to check.

Script1
:local timetest [/system clock get time]
:local GST

:if (($timetest>09:00:00)and($timetest<17:00:00)) do={set $GST “1”} else= {set $GST “0”}
:log info “GST Status = $GST”

Works as expected.

Now Script2
:local timetest [/system clock get time]
:local GST
:local V1 “($timetest>09:00:00)and($timetest<17:00:00)”
:log info $V1

:if ($V1) do={set $GST “1”} else= {set $GST “0”}
:log info “GST Status = $GST”

This Fails right after showing me the time range.

Now if I change everything to :global… I can paste right into a terminal and see where the error is…
[admin@MikroTik] > :global timetest [/system clock get time]
[admin@MikroTik] > :global GST
[admin@MikroTik] > :global V1 “($timetest>09:00:00)and($timetest<17:00:00)”
[admin@MikroTik] > :log info $V1
[admin@MikroTik] >
[admin@MikroTik] > :if ($V1) do={set $GST “1”} else= {set $GST “0”}
conditional is not boolean
[admin@MikroTik] > :log info “GST Status = $GST”

Looking at my /system script enviornment
[admin@MikroTik] > /system script environment print

NAME VALUE

0 GST
3 V1 (08:58:51>09:00:00)and(08:58:51<17:00:00)
9 timetest 08:58:51

This means that V1 is not processed once imported to
:if ($V1) do={set $GST “1”} else= {set $GST “0”}

What is the proper format to get $V1 processed inline there for the rest of the function?

You V1 value is string:
:global V1 “($timetest>09:00:00)and($timetest<17:00:00)”

Of course it cannot be used as boolean.

MRZ.

Yes… it’s a string. And the line is not processing it.
It’s value is supposed to be placed inline where V1 is and it is not processed as such.

So what is supposed to be there to make that work?

What exactly you want to do?
You need to compare string value from V1 to something to return boolean.

This line…
:if ($V1) do={set $GST “1”} else= {set $GST “0”}

Needs to be treated the same as this line
:if (($timetest>09:00:00)and($timetest<17:00:00)) do={set $GST “1”} else= {set $GST “0”}

My day of the week script is writing $V1 each day. So the script needs to PICK THAT TEXT, then treat it as if it was written directly in the function.

Either use :parse or better option write a function. See examples in the manual
https://wiki.mikrotik.com/wiki/Manual:Scripting#Functions

now i see what you’re getting to. try this way

[me@router] > :global V1 [parse ":if (($timetest>09:00:00 ) and ($timetest<17:00:00 )) do={:put (1=1);return (1=1);} else={:put (1=0);return (1=0);}" ] 
[me@router] > :put $V1                                                    
(eval /ifcondition=(&& (> 15:41:59 09:00:00) (< 15:41:59 17:00:00));do=;(eval (eval /putmessage=(= 1 1)) (eval /returnvalue=(= 1 1)));else=;(eval (eval /putmessage=(= 1 0)) (eval /returnvalue=(= 1 0))))
[me@router] > $V1
true

now V1 will be a piece of code you can execute. but i doubt it will be evaluated inside the “if” statement.

This is surprisingly messy.

The string I need is pretty small, and needs to be updated per day.
Hence the desire to write the “string” per day then have the script reference “Today’s String” and plug it into the function.

Is it really this convoluted?

So how can I use that true false?
:local TT1 (Result of $V1)

The other problem is that I need to adjust that function each day.

This morning’s progress

[admin@MikroTik] /system script environment> print

NAME VALUE

0 TT1 ;(eval (eval /returnvalue=(&& (> $timetest 09:00:00) (< $timetest 17:00:00))))

:global timetest [/system clock get time]
:log info $timetest
:local GST
:global TT1
:local TTR [:put [$TT1]]
:log info “TTR result = $TTR”

:if ($TTR = true) do={set $GST “1”} else= {set $GST “0”}
:log info “GST Status = $GST”

Set your schedule…
This example will set GuestTime to True From 9:00AM-5:00PM and From 8:00PM-11:59:59PM.
:global timetest [/system clock get time]
:global TT1 do={ :return (($timetest>09:00:00)and($timetest<17:00:00)||($timetest>20:00:00))}
:local GuestTime [:put [$TT1]]