When you assign a value to a name in an event handler, like this:
on view do
p:1+2
end
…when Decker decides the thing is being viewed:
- it calls the
viewevent handler - it creates a new name
pinside that event handler - it assigns the value 3 to
p - the event handler ends
pvanishes along with it
If you have some other event handler somewhere else, like on click do ... end, that event handler does not have access to p, it can’t use the value. If you say p:2*3 in that event handler, it will have its own p that will also vanish when the event handler completes.
In the first code block in your comment, you have:
on view do
p:"%p" parse "%e" format sys.now utc_offset:1
p.hour:24%utc_offset+p.hour b:(p.hour)
me.text:"%f:" format b
end
That creates a p with date-time information in it, it adjusts the hour part of that date time, it uses the p for some text formatting, and then the event handler ends and that p is lost.
In your second code-block, which I assume is from a button’s on click do ... event handler, you have:
...
p:"%p" parse "%e" format sys.now
...
if (p.hour=12)&(p.minute=13)
...
Because that’s a separate event handler, that’s a separate and unrelated p, and its p.hour has not been modified. Every event handler where you want to use the modified time, you need to modify it again.
Also, a little further down:
...
elseif ((p.hour) <10) & ((p.hour) >20)
...
I don’t think the hour can be less than ten and greater than 20. Perhaps you wanted to switch those around to be “greater than 10 and less than 20”?
Assuming that’s what you want, here’s a button that behaves that way (although it uses Decker’s built-in alert[] rather than the dd.say[] module):
%%WGT0{"w":[{"name":"timelock","type":"button","size":[95,20],"pos":[226,161],"script":"on click do\n p:\"%p\" parse \"%e\" format sys.now utc_offset:1 \n p.hour:24%utc_offset+p.hour\n\n if ((p.hour) >10) & ((p.hour) <20)\n alert[\"###ACCES AUTORISE ENTRE 20H ET 10H###\"]\n else\n alert[\"###ACCES INTERDIT ENTRE 10H ET 20H###\"]\n end\nend","text":"Attempt Unlock"}],"d":{}}
Copy that text to the clipboard, then in Decker you should be able to switch to the widget-editing mode and use Edit → Paste Widgets to add the button to the current card, where you can poke at it.