Page 1 of 1

:[Variable]_OnChange

PostPosted: Fri Apr 26, 2013 12:17 pm
by smokinbanger
We have some really nice features like
Code: Select all
:CommandLine_OnChange
:ObjectName_OnOpen/OnClose
etc.
I think it would be awesome to expand these "OnChange" Subroutines to include a
Code: Select all
:[Variable]_OnChange
where [Variable] could be any Neobook (User created or global) variable. The sub would be executed any time the variables changes with the exception of being cleared (SetVar "[Variable]" "").
This would prove VERY useful for things like error logging.
Example:
Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
:[LastError]_OnChange
     FileWrite "[PubDir]ErrorLog.txt" "Append" "[DateShort] [Time] [LastError]"
Return

:[DbpError]_OnChange
     FileWrite "[PubDir]ErrorLog.txt" "Append" "[DateShort] [Time] [LastError]"
Return
Parsed in 0.006 seconds, using GeSHi 1.0.8.10

I'm not sure how easy it would be to implement this (or if it's even possible), but it would sure be COOL! 8)

Re: :[Variable]_OnChange

PostPosted: Sat Apr 27, 2013 4:44 am
by CN_Iceman
Good idea!!

Re: :[Variable]_OnChange

PostPosted: Sat Apr 27, 2013 5:28 am
by dec
Hello,

Maybe I'am wrong, but, I think this it's not a good idea, at the least in terms of efficiency. Check for a variable change have a cost, and check for every variable changes... and call the appropiate subroutines (after test if really exists)... probably take down the publication performance. NeoBook provide mechanism like the "Timer" object that can be used, for example, to check certain variable changes. Then, you can also call the appropiate subroutine or just do whatever you wanted. With a reasonable Timer interval and just the needed variables checks probably the publication continue running without performance losses.

Re: :[Variable]_OnChange

PostPosted: Sat Apr 27, 2013 6:41 am
by mishem
In this topic I was trying to explain how you can monitor variables.
Here you can download a sample

In general, a good idea. But it would be better to add events for objects.
The mouse button is pressed, the button is held down, the scroll wheel mouse and monitor. Then monitor objects and variables disappear.

Re: :[Variable]_OnChange

PostPosted: Sat Apr 27, 2013 7:56 am
by Gaev
Interesting discussion ... I faintly recall making a similar suggestion years ago.

If the main purpose of requesting such a feature is to be able to custom handle errors ..

a) the use of the Timer object might not work ... as NeoBook can handle many script commands between Timer Intervals.

b) might be a better suggestion to ask for an onError subroutine facility

In any case, the tricky part would be the handling of 'subsequent errors' ... i.e. errors encountered within the onError subroutine ... abort further processing of the subroutine ? ... abort all processing of the Application ? ... otherwise, could get into an endless loop.

Also, what is to be done after the onError routine is successfully serviced ? ... return to script command following the erroneous command ? ... skip the rest of the script section ?


If the request was more global (i.e. specify routine for change to ANY SPECIFIED NeoBook variable) ... what happens when the variable in question is updated inside the associated subroutine ? ... or SPECIFIED variable B is updated within the onChange subroutine of variable A ?

Re: :[Variable]_OnChange

PostPosted: Sat Apr 27, 2013 8:46 am
by smokinbanger
Gaev wrote:b) might be a better suggestion to ask for an onError subroutine facility
Good idea, too.

Gaev wrote:In any case, the tricky part would be the handling of 'subsequent errors' ... i.e. errors encountered within the onError subroutine ... abort further processing of the subroutine ? ... abort all processing of the Application ? ... otherwise, could get into an endless loop.
I didn't think of that one but yes, there could be a potential endless loop.

Gaev wrote:Also, what is to be done after the onError routine is successfully serviced ? ... return to script command following the erroneous command ? ... skip the rest of the script section ?
Most likely Return but every situation is different...


Gaev wrote:If the request was more global (i.e. specify routine for change to ANY SPECIFIED NeoBook variable) ... what happens when the variable in question is updated inside the associated subroutine ? ... or SPECIFIED variable B is updated within the onChange subroutine of variable A ?
We would have to be carefull not not create "conflicting" :[Variable]_OnChange subs; If we had
Code: Select all
 :[VarA]_OnChange
SetVar "[VarB]" "123etc"
Return
and
Code: Select all
:[VarB]_OnChange
SetVar "[VarA]" "etc123"
Return
it could alse create an endless loop :twisted:

Re: :[Variable]_OnChange

PostPosted: Mon Apr 29, 2013 11:50 am
by Neosoft Support
It's an interesting idea, but it could impact performance quite a bit as variables change constantly. What might work would be to add individual variables to a watch list and trigger a subroutine only when one of those variables changes.

Re: :[Variable]_OnChange

PostPosted: Mon Apr 29, 2013 12:40 pm
by Gaev
What might work would be to add individual variables to a watch list and trigger a subroutine only when one of those variables changes
That would be a big improvement to NeoBook ... but Developers need to be careful about the same variable being part of other Objects ... could trigger more than one event ... which one comes first ? ... and what happens if the first event code changes the variable again ?